Skip to content

Commit

Permalink
Merge pull request #10 from Qfeed-Dev/feature/#1
Browse files Browse the repository at this point in the history
[Fix] 로그인 이후 라우팅 체크 문제
  • Loading branch information
hamo-o authored Aug 12, 2023
2 parents 5d41512 + 238d77d commit b581e30
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/hooks/account/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@ export const useAuth = () => {
const { user, isLoading } = useUserQuery();
const [isActive, setIsActive] = useState<boolean | undefined>(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
};
Expand Down

0 comments on commit b581e30

Please sign in to comment.