From 922de40134d1dbedcd6fb73cae29495271b17ec3 Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Mon, 14 Apr 2025 16:12:27 +0300 Subject: [PATCH] fix(useapplelogin): add timeout for close --- src/routes/Intro/useAppleLogin.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/routes/Intro/useAppleLogin.ts b/src/routes/Intro/useAppleLogin.ts index 7d5465838..e6a39cbb9 100644 --- a/src/routes/Intro/useAppleLogin.ts +++ b/src/routes/Intro/useAppleLogin.ts @@ -52,7 +52,17 @@ const useAppleLogin = (): [() => Promise, () => void] => { 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) => { + clearTimeout(timeoutId); + started.current = false; + if (response.authorization) { try { const idToken = response.authorization.id_token; @@ -84,6 +94,10 @@ const useAppleLogin = (): [() => Promise, () => void] => { } else { reject(new Error('No authorization received from Apple')); } + }).catch((error) => { + clearTimeout(timeoutId); + started.current = false; + reject(error); }); }); }, []);