260508_09_ENH: 새로고침 시 로그인 풀리는 문제 수정 중
This commit is contained in:
@@ -7,14 +7,29 @@ import type { LoginUser } from "@/types/auth";
|
|||||||
import { getLocalStorage } from "@/store/storage/secure-storage";
|
import { getLocalStorage } from "@/store/storage/secure-storage";
|
||||||
import { StorageKeys } from "@/store/storage/storage-keys";
|
import { StorageKeys } from "@/store/storage/storage-keys";
|
||||||
|
|
||||||
|
const isAuthDebugEnabled = () =>
|
||||||
|
typeof window !== "undefined" && localStorage.getItem("kfpa:debugAuth") === "1";
|
||||||
|
|
||||||
export const useAuth = () => {
|
export const useAuth = () => {
|
||||||
const [auth, setAuth] = useAtom(authStateAtom);
|
const [auth, setAuth] = useAtom(authStateAtom);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (isAuthDebugEnabled()) {
|
||||||
|
console.log("[auth] current atom state", auth);
|
||||||
|
console.log("[auth] raw storage value", localStorage.getItem(StorageKeys.AuthState));
|
||||||
|
}
|
||||||
|
|
||||||
if (auth.user != null) return;
|
if (auth.user != null) return;
|
||||||
|
|
||||||
const stored = getLocalStorage(StorageKeys.AuthState) as AuthState | null;
|
const stored = getLocalStorage(StorageKeys.AuthState) as AuthState | null;
|
||||||
|
if (isAuthDebugEnabled()) {
|
||||||
|
console.log("[auth] parsed storage value", stored);
|
||||||
|
}
|
||||||
|
|
||||||
if (stored?.user != null) {
|
if (stored?.user != null) {
|
||||||
|
if (isAuthDebugEnabled()) {
|
||||||
|
console.log("[auth] restoring user from storage", stored.user);
|
||||||
|
}
|
||||||
setAuth(stored);
|
setAuth(stored);
|
||||||
}
|
}
|
||||||
}, [auth.user, setAuth]);
|
}, [auth.user, setAuth]);
|
||||||
|
|||||||
Reference in New Issue
Block a user