260508_07_ENH: 새로고침 시 로그인 풀리는 문제 수정 중
This commit is contained in:
@@ -1,13 +1,24 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback } from "react";
|
||||
import { useCallback, useEffect } from "react";
|
||||
import { useAtom } from "jotai";
|
||||
import { authStateAtom, type AuthState } from "@/store/jotai/auth";
|
||||
import type { LoginUser } from "@/types/auth";
|
||||
import { getLocalStorage } from "@/store/storage/secure-storage";
|
||||
import { StorageKeys } from "@/store/storage/storage-keys";
|
||||
|
||||
export const useAuth = () => {
|
||||
const [auth, setAuth] = useAtom(authStateAtom);
|
||||
|
||||
useEffect(() => {
|
||||
if (auth.user != null) return;
|
||||
|
||||
const stored = getLocalStorage(StorageKeys.AuthState) as AuthState | null;
|
||||
if (stored?.user != null) {
|
||||
setAuth(stored);
|
||||
}
|
||||
}, [auth.user, setAuth]);
|
||||
|
||||
// 로그인 성공 후 LoginResponse 를 바로 넣어줄 수 있게
|
||||
const setFromLoginResponse = useCallback(
|
||||
(res: LoginUser) => {
|
||||
@@ -37,4 +48,4 @@ export const useAuth = () => {
|
||||
setFromLoginResponse,
|
||||
logout,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user