fix session persist bug
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 8s
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 8s
This commit is contained in:
+12
-2
@@ -19,8 +19,18 @@ import type { AuthUser } from "./types/user";
|
|||||||
export const TOKEN_KEY = "sarlink_token";
|
export const TOKEN_KEY = "sarlink_token";
|
||||||
export const USER_KEY = "sarlink_user";
|
export const USER_KEY = "sarlink_user";
|
||||||
|
|
||||||
export const tokenAtom = atomWithStorage<string | null>(TOKEN_KEY, null);
|
// `getOnInit: true` is REQUIRED here. Without it, jotai defers reading
|
||||||
export const userAtom = atomWithStorage<AuthUser | null>(USER_KEY, null);
|
// 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). */
|
/** Read the raw token (used by the axios request interceptor). */
|
||||||
export function getToken(): string | null {
|
export function getToken(): string | null {
|
||||||
|
|||||||
Reference in New Issue
Block a user