From 303dd9858b80a9196108e83bafcd3aed9d1b76ca Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Mon, 14 Apr 2025 19:29:12 +0300 Subject: [PATCH] refactor(useapplelogin): handle error cases --- src/routes/Intro/Intro.js | 6 +++++- src/routes/Intro/useAppleLogin.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/routes/Intro/Intro.js b/src/routes/Intro/Intro.js index 01ca5eab7..716fe0f0d 100644 --- a/src/routes/Intro/Intro.js +++ b/src/routes/Intro/Intro.js @@ -129,7 +129,11 @@ const Intro = ({ queryParams }) => { }) .catch((error) => { closeLoaderModal(); - dispatch({ type: 'error', error: error.message }); + if (error.error === 'popup_closed_by_user') { + dispatch({ type: 'error', error: 'Apple login popup was closed.' }); + } else { + dispatch({ type: 'error', error: error.error }); + } }); }, []); const cancelLoginWithApple = React.useCallback(() => { diff --git a/src/routes/Intro/useAppleLogin.ts b/src/routes/Intro/useAppleLogin.ts index 4128ee259..580ec2d86 100644 --- a/src/routes/Intro/useAppleLogin.ts +++ b/src/routes/Intro/useAppleLogin.ts @@ -1,4 +1,4 @@ -import { useCallback, useRef } from 'react'; +import { useCallback, useEffect, useRef } from 'react'; import { jwtDecode, JwtPayload } from 'jwt-decode'; type AppleLoginResponse = { @@ -94,6 +94,10 @@ const useAppleLogin = (): [() => Promise, () => void] => { started.current = false; }, []); + useEffect(() => { + return () => stop(); + }, []); + return [start, stop]; };