fix(useapplelogin): add timeout for close

This commit is contained in:
Timothy Z. 2025-04-14 16:12:27 +03:00
parent 52dc7722ad
commit 922de40134

View file

@ -52,7 +52,17 @@ const useAppleLogin = (): [() => Promise<AppleLoginResponse>, () => void] => {
usePopup: true, usePopup: true,
}); });
const timeoutId = setTimeout(() => {
if (started.current) {
started.current = false;
reject(new Error('Apple login popup was closed'));
}
}, 1000);
window.AppleID.auth.signIn().then((response: AppleSignInResponse) => { window.AppleID.auth.signIn().then((response: AppleSignInResponse) => {
clearTimeout(timeoutId);
started.current = false;
if (response.authorization) { if (response.authorization) {
try { try {
const idToken = response.authorization.id_token; const idToken = response.authorization.id_token;
@ -84,6 +94,10 @@ const useAppleLogin = (): [() => Promise<AppleLoginResponse>, () => void] => {
} else { } else {
reject(new Error('No authorization received from Apple')); reject(new Error('No authorization received from Apple'));
} }
}).catch((error) => {
clearTimeout(timeoutId);
started.current = false;
reject(error);
}); });
}); });
}, []); }, []);