refactor: switch auth data from localStorage to sessionStorage

Aligns user and permissions storage with the existing sessionStorage-based
token model. Eliminates the dual-write pattern and stale cross-session data.
This commit is contained in:
2026-07-28 02:16:24 +00:00
parent 739253b2e5
commit c4a10c7129
5 changed files with 8 additions and 10 deletions
+1 -2
View File
@@ -47,7 +47,7 @@ function clearAuthTokens() {
sessionStorage.removeItem('vw:access_ttl');
sessionStorage.removeItem('vw:session_id');
sessionStorage.removeItem('vw:user');
localStorage.removeItem('vw:user');
sessionStorage.removeItem('vw:user');
if (typeof window.__authRefreshTimer__ !== 'undefined') {
clearTimeout(window.__authRefreshTimer__);
window.__authRefreshTimer__ = undefined;
@@ -112,7 +112,6 @@ async function tryRefreshToken() {
}
if (json.data.user) {
sessionStorage.setItem('vw:user', JSON.stringify(json.data.user));
localStorage.setItem('vw:user', JSON.stringify(json.data.user));
}
return true;
} catch {
+3 -4
View File
@@ -46,10 +46,9 @@ export async function checkSession() {
if (result.ok) {
const { user, permissions } = result.data || {};
if (user) {
localStorage.setItem('vw:user', JSON.stringify(user));
sessionStorage.setItem('vw:user', JSON.stringify(user));
if (permissions) {
localStorage.setItem('vw:permissions', JSON.stringify(permissions));
sessionStorage.setItem('vw:permissions', JSON.stringify(permissions));
}
return true;
}
@@ -125,9 +124,9 @@ export function handleLoginSuccess(data, redirectPath = '/dashboard') {
sessionStorage.setItem('vw:session_id', tokens.session_id);
}
if (user) {
localStorage.setItem('vw:user', JSON.stringify(user));
sessionStorage.setItem('vw:user', JSON.stringify(user));
if (permissions) {
localStorage.setItem('vw:permissions', JSON.stringify(permissions));
sessionStorage.setItem('vw:permissions', JSON.stringify(permissions));
}
}
scheduleTokenRefresh();