From 4f0bac37c171fbed71e4f99b2e8987143e2e7a7b Mon Sep 17 00:00:00 2001 From: hamo-o Date: Sun, 13 Aug 2023 01:43:49 +0900 Subject: [PATCH] fix: fix redirect (401) --- src/hooks/account/useAuth.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/hooks/account/useAuth.ts b/src/hooks/account/useAuth.ts index 0e12199..de75eda 100644 --- a/src/hooks/account/useAuth.ts +++ b/src/hooks/account/useAuth.ts @@ -21,24 +21,22 @@ export const useAuth = () => { const { user, isLoading } = useUserQuery(); const [isActive, setIsActive] = useState(undefined); - useEffect(() => { - if (!isLoading && user !== undefined) { - setIsActive(useIsActive(user)); - } - }, [isLoading, user]); - const kakaoMutation = useMutation(getAccessToken, { onSuccess: (data: any) => { - if (isActive !== undefined) { - setAccessToken(data.accessToken); - isActive ? router.push("/") : router.push("/sign-up/default"); - } + setAccessToken(data.accessToken); }, onError: (error: any) => { alert(error); } }); + useEffect(() => { + if (!kakaoMutation.isLoading && !isLoading && user !== undefined) { + setIsActive(useIsActive(user)); + isActive ? router.push("/") : router.push("/sign-up/default"); + } + }, [kakaoMutation.isLoading, isLoading, user, isActive, router]); + return { kakaoMutation };