fix: isolate account state and ignore stale session responses

This commit is contained in:
2026-09-06 08:46:05 +03:00
parent 05c7e7ecdc
commit a291b186df
5 changed files with 109 additions and 98 deletions
+2
View File
@@ -53,8 +53,10 @@ export async function restoreSession() {
if (!token) return null;
try {
const res = await fetch('/api/auth/me', { headers: { Authorization: `Bearer ${token}` } });
if (getToken() !== token) return getStoredUser();
if (!res.ok) { clearSession(); return null; }
const data = await res.json();
if (getToken() !== token) return getStoredUser();
if (data.success) { setSession(token, data.user); return data.user; }
clearSession();
return null;