Skip to content

Commit 9b2fbcf

Browse files
fix(ui): logout should clear all the stale state and clear tokens
1 parent 3e1f6d0 commit 9b2fbcf

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

openmetadata-ui/src/main/resources/ui/src/components/Auth/AuthProviders/AuthProvider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import {
8181
import { getPathNameFromWindowLocation } from '../../../utils/RouterUtils';
8282
import { escapeESReservedCharacters } from '../../../utils/StringsUtils';
8383
import {
84+
clearOidcToken,
8485
getOidcToken,
8586
getRefreshToken,
8687
setOidcToken,
@@ -264,7 +265,7 @@ export const AuthProvider = ({
264265

265266
const resetUserDetails = (forceLogout = false) => {
266267
setCurrentUser({} as User);
267-
setOidcToken('');
268+
clearOidcToken();
268269
setRefreshToken('');
269270
setIsAuthenticated(false);
270271
setApplicationLoading(false);

openmetadata-ui/src/main/resources/ui/src/utils/SwTokenStorageUtils.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ const setAppState = async (state: AppState): Promise<void> => {
6767
}
6868
};
6969

70+
const clearAppState = async (): Promise<void> => {
71+
try {
72+
if (isServiceWorkerAvailable()) {
73+
await swTokenStorage.removeItem(APP_STATE_KEY);
74+
} else {
75+
// Fallback for browsers that don't support SW/IndexedDB
76+
localStorage.removeItem(APP_STATE_KEY);
77+
}
78+
} catch {
79+
// Storage failures are intentionally ignored to prevent auth flows from breaking.
80+
// Token persistence is treated as "best effort" - if storage fails, the user
81+
// may need to re-authenticate, but core functionality continues working.
82+
}
83+
};
84+
7085
export const getOidcToken = async (): Promise<string> => {
7186
try {
7287
const state = await getAppState();
@@ -110,3 +125,13 @@ export const setRefreshToken = async (token: string): Promise<void> => {
110125
// may need to re-authenticate, but core functionality continues working.
111126
}
112127
};
128+
129+
export const clearOidcToken = async (): Promise<void> => {
130+
try {
131+
await clearAppState();
132+
} catch {
133+
// Storage failures are intentionally ignored to prevent auth flows from breaking.
134+
// Token persistence is treated as "best effort" - if storage fails, the user
135+
// may need to re-authenticate, but core functionality continues working.
136+
}
137+
};

0 commit comments

Comments
 (0)