fix: automatic SSO sign-in fails with a state mismatch after the session expires (#33791)

With OAUTH_AUTO_REDIRECT on, an expired or invalid session sent the browser to the identity provider while the sign-out request was still running. When that request finished it wiped the login state, so the callback failed and the user landed on the sign-in page with an error. The sign-out now completes before the redirect, so the user is signed back in without an error.

Fixes #33783
This commit is contained in:
Classic298 authored and GitHub committed 2026-11-06 08:05:32 +09:00
1 parent 8ebc96d3d8
commit 2fb2e9ea27
1 file changed
+5 -4
+5 -4
View File
@@ -1024,7 +1024,7 @@
}
};
const clearExpiredSession = () => {
const clearExpiredSession = async () => {
if (isAuthRedirectInProgress) {
return;
}
@@ -1034,13 +1034,14 @@
clearInterval(tokenTimer);
tokenTimer = null;
}
// Await sign-out so it cannot clear the state of the new OAuth login
await userSignOut().catch((error) => {
console.error('Error signing out expired session:', error);
});
user.set(null);
localStorage.removeItem('token');
// Clear the OAuth token cookie so /auth doesn't auto-login and redirect-loop
document.cookie = 'token=; Max-Age=0; path=/';
userSignOut().catch((error) => {
console.error('Error signing out expired session:', error);
});
toast.error($i18n.t('Session expired. Please sign in again.'));
isAuthRedirectInProgress = false;
};