mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
Refactor ProfilePage to remove unused API calls and optimize user data handling
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user