mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-05-12 00:50:39 +00:00
fix(useapplelogin): add timeout for close
This commit is contained in:
parent
52dc7722ad
commit
922de40134
1 changed files with 14 additions and 0 deletions
|
|
@ -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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue