fix session persist bug
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 8s

This commit is contained in:
2026-08-03 19:06:21 +05:00
parent 7d94a15ca3
commit 46214c55fc
+12 -2
View File
@@ -19,8 +19,18 @@ import type { AuthUser } from "./types/user";
export const TOKEN_KEY = "sarlink_token";
export const USER_KEY = "sarlink_user";
export const tokenAtom = atomWithStorage<string | null>(TOKEN_KEY, null);
export const userAtom = atomWithStorage<AuthUser | null>(USER_KEY, null);
// `getOnInit: true` is REQUIRED here. Without it, jotai defers reading
// localStorage until the atom is mounted by a React component, so the
// synchronous `store.get()` calls in `getToken()` / `isAuthenticated()`
// (used by RouteGuard, RootRedirect, and the axios interceptor during the
// first render on a page refresh) would see the initial `null` instead of the
// persisted token — bouncing an already-authenticated user to signin on reload.
export const tokenAtom = atomWithStorage<string | null>(TOKEN_KEY, null, undefined, {
getOnInit: true,
});
export const userAtom = atomWithStorage<AuthUser | null>(USER_KEY, null, undefined, {
getOnInit: true,
});
/** Read the raw token (used by the axios request interceptor). */
export function getToken(): string | null {