refactor(useapplelogin): handle error cases

This commit is contained in:
Timothy Z. 2025-04-14 19:29:12 +03:00
parent 3aac148258
commit 303dd9858b
2 changed files with 10 additions and 2 deletions

View file

@ -129,7 +129,11 @@ const Intro = ({ queryParams }) => {
}) })
.catch((error) => { .catch((error) => {
closeLoaderModal(); 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(() => { const cancelLoginWithApple = React.useCallback(() => {

View file

@ -1,4 +1,4 @@
import { useCallback, useRef } from 'react'; import { useCallback, useEffect, useRef } from 'react';
import { jwtDecode, JwtPayload } from 'jwt-decode'; import { jwtDecode, JwtPayload } from 'jwt-decode';
type AppleLoginResponse = { type AppleLoginResponse = {
@ -94,6 +94,10 @@ const useAppleLogin = (): [() => Promise<AppleLoginResponse>, () => void] => {
started.current = false; started.current = false;
}, []); }, []);
useEffect(() => {
return () => stop();
}, []);
return [start, stop]; return [start, stop];
}; };