Refactor ProfilePage to remove unused API calls and optimize user data handling

This commit is contained in:
Estifo77
2026-08-08 11:13:03 +03:00
parent 938bc94ce0
commit 1116e57a8d
2 changed files with 7 additions and 24 deletions

View File

@@ -30,6 +30,7 @@ export function AuthBootstrap({ children }: { children: ReactNode }) {
dispatch(hydrateAuth());
const token = authStorage.getToken();
const cachedUser = authStorage.getUser<AuthUser>();
if (!token) {
if (!cancelled) setReady(true);
return;
@@ -42,7 +43,12 @@ export function AuthBootstrap({ children }: { children: ReactNode }) {
if (response.ok) {
const user = (await response.json()) as AuthUser;
if (!cancelled) dispatch(setUser(user));
// Keep the persisted session as the source of truth when it is
// available. A successful profile update writes it immediately,
// while `/auth/me` can briefly return a stale read and otherwise
// undo that update on every page refresh. We still make this call
// to validate the token and clear invalid sessions below.
if (!cancelled && !cachedUser) dispatch(setUser(user));
} else if (response.status === 401 || response.status === 403) {
// Expired or revoked — drop it so the user gets a login screen
// instead of a dead end.