From 2fb2e9ea27fefcc5c3a7c4192eb3e1b472e21e32 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Fri, 6 Nov 2026 00:05:32 +0100 Subject: [PATCH] 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 --- src/routes/+layout.svelte | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 02c3d1bf64..4092eac111 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -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; };