From eb76696d9748b07c79b07736ac5d26d922107725 Mon Sep 17 00:00:00 2001 From: Stanislav Deviatykh Date: Wed, 22 Oct 2025 00:09:57 +0300 Subject: [PATCH] correctly clear scope --- client/src/lib/auth.ts | 8 +++++--- client/src/lib/hooks/useConnection.ts | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/client/src/lib/auth.ts b/client/src/lib/auth.ts index edd3ef58..79750112 100644 --- a/client/src/lib/auth.ts +++ b/client/src/lib/auth.ts @@ -122,6 +122,11 @@ export const saveScopeToSessionStorage = ( } }; +export const clearScopeFromSessionStorage = (serverUrl: string) => { + const key = getServerSpecificKey(SESSION_KEYS.SCOPE, serverUrl); + sessionStorage.removeItem(key); +}; + export class InspectorOAuthClientProvider implements OAuthClientProvider { constructor(protected serverUrl: string) { // Save the server URL to session storage @@ -243,9 +248,6 @@ export class InspectorOAuthClientProvider implements OAuthClientProvider { sessionStorage.removeItem( getServerSpecificKey(SESSION_KEYS.CODE_VERIFIER, this.serverUrl), ); - sessionStorage.removeItem( - getServerSpecificKey(SESSION_KEYS.SCOPE, this.serverUrl), - ); } } diff --git a/client/src/lib/hooks/useConnection.ts b/client/src/lib/hooks/useConnection.ts index f6d42380..bd15e080 100644 --- a/client/src/lib/hooks/useConnection.ts +++ b/client/src/lib/hooks/useConnection.ts @@ -46,6 +46,7 @@ import { InspectorOAuthClientProvider, saveClientInformationToSessionStorage, saveScopeToSessionStorage, + clearScopeFromSessionStorage, discoverScopes, } from "../auth"; import { @@ -144,6 +145,11 @@ export function useConnection({ }, [oauthClientId, oauthClientSecret, sseUrl]); useEffect(() => { + if (!oauthScope) { + clearScopeFromSessionStorage(sseUrl); + return; + } + saveScopeToSessionStorage(sseUrl, oauthScope); }, [oauthScope, sseUrl]);