diff --git a/frontend/src/auth.ts b/frontend/src/auth.ts index f172bff..44d2500 100644 --- a/frontend/src/auth.ts +++ b/frontend/src/auth.ts @@ -16,6 +16,8 @@ import { } from "@atcute/identity-resolver"; const STORAGE_KEY = "atvouch_did"; +const AUTH_VERSION_KEY = "authVersion"; +const AUTH_VERSION = 1; export function initOAuth() { configureOAuth({ @@ -61,6 +63,7 @@ export async function handleCallback(): Promise { const result = await finalizeAuthorization(params); const agent = new OAuthUserAgent(result.session); localStorage.setItem(STORAGE_KEY, agent.sub); + localStorage.setItem(AUTH_VERSION_KEY, String(AUTH_VERSION)); return agent; } @@ -68,11 +71,19 @@ export async function resumeSession(): Promise { const did = localStorage.getItem(STORAGE_KEY); if (!did) return null; + const storedVersion = parseInt(localStorage.getItem(AUTH_VERSION_KEY) ?? "0", 10); + if (storedVersion < AUTH_VERSION) { + localStorage.removeItem(STORAGE_KEY); + localStorage.removeItem(AUTH_VERSION_KEY); + return null; + } + try { const session = await getSession(did as Did, { allowStale: true }); return new OAuthUserAgent(session); } catch { localStorage.removeItem(STORAGE_KEY); + localStorage.removeItem(AUTH_VERSION_KEY); return null; } } @@ -86,4 +97,5 @@ export async function logout(agent: OAuthUserAgent): Promise { } await deleteStoredSession(did); localStorage.removeItem(STORAGE_KEY); + localStorage.removeItem(AUTH_VERSION_KEY); }