260508_09_ENH: 새로고침 시 로그인 풀리는 문제 수정 중

This commit is contained in:
2026-05-08 11:08:22 +09:00
parent c7b0655ec2
commit e224455dea

View File

@@ -7,14 +7,29 @@ import type { LoginUser } from "@/types/auth";
import { getLocalStorage } from "@/store/storage/secure-storage";
import { StorageKeys } from "@/store/storage/storage-keys";
const isAuthDebugEnabled = () =>
typeof window !== "undefined" && localStorage.getItem("kfpa:debugAuth") === "1";
export const useAuth = () => {
const [auth, setAuth] = useAtom(authStateAtom);
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;
const stored = getLocalStorage(StorageKeys.AuthState) as AuthState | null;
if (isAuthDebugEnabled()) {
console.log("[auth] parsed storage value", stored);
}
if (stored?.user != null) {
if (isAuthDebugEnabled()) {
console.log("[auth] restoring user from storage", stored.user);
}
setAuth(stored);
}
}, [auth.user, setAuth]);