From 9157c13f5cba94ce956e68ffe4a24b054c021c0a Mon Sep 17 00:00:00 2001 From: Siwoo Lee Date: Tue, 4 Jun 2024 21:27:12 +0900 Subject: [PATCH] Fix: signIn nav error --- src/components/start/SignIn.tsx | 13 ++++++++++--- src/hooks/useGetUserInfo.ts | 3 ++- src/pages/Page-Start.tsx | 7 +++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/start/SignIn.tsx b/src/components/start/SignIn.tsx index 5716c95..a2eee15 100644 --- a/src/components/start/SignIn.tsx +++ b/src/components/start/SignIn.tsx @@ -6,6 +6,7 @@ import { SIGININ_TEXTS } from '@/constants/start'; import { getSocialAuth, ddockerSignIn, getMyInfo } from '@/api/user'; import { iconPropsGenerator } from '@/utils/iconPropsGenerator'; import { useNavigateTo } from '@/hooks/useNavigateTo'; +import { useCachedUserInfo } from '@/hooks/useCachedUserInfo'; import useGetCacheData from '@/hooks/useGetCacheData'; import { ddockerSignInType } from '@/types/types'; @@ -25,6 +26,7 @@ const { signInBtn, startText } = SIGININ_TEXTS; const SignIn = () => { const [searchParams] = useSearchParams(); + const { accessToken } = useCachedUserInfo(); const code = searchParams.get('code'); const navToHome = useNavigateTo('/'); const navToSignUp = useNavigateTo('/start/2'); @@ -40,9 +42,13 @@ const SignIn = () => { } }; - const verifyMembership = async () => { + const verifyMembership = async (accessToken: string | null) => { const social = await useGetCacheData('user', '/social'); - const res = code && social && (await ddockerSignIn(code, social.cacheData)); + const res = + !accessToken && + code && + social && + (await ddockerSignIn(code, social.cacheData)); if (res) { const { accessToken } = res as ddockerSignInType; const singIn = async () => { @@ -50,10 +56,11 @@ const SignIn = () => { }; return accessToken ? singIn() : navToSignUp(); } + accessToken && navToHome(); }; useEffect(() => { - verifyMembership(); + verifyMembership(accessToken); }, []); return ( diff --git a/src/hooks/useGetUserInfo.ts b/src/hooks/useGetUserInfo.ts index b6329b5..daaa45e 100644 --- a/src/hooks/useGetUserInfo.ts +++ b/src/hooks/useGetUserInfo.ts @@ -39,7 +39,8 @@ function useGetUserInfo(profileId?: string | number | undefined) { res && setCachedUser(res.data); return; } - userData && setCachedUser(userData); + + return userData && setCachedUser(userData); }; useEffect(() => { diff --git a/src/pages/Page-Start.tsx b/src/pages/Page-Start.tsx index b9609af..2ea01d3 100644 --- a/src/pages/Page-Start.tsx +++ b/src/pages/Page-Start.tsx @@ -15,7 +15,7 @@ const allowedPages = ['1', '2', '3']; const Start = () => { useShowFooter(false); useCancelSignUp(); - const { accessToken, userData } = useCachedUserInfo(); + const { userData } = useCachedUserInfo(); const { id } = useParams(); const notAllowedPages = id && !allowedPages.includes(id); @@ -25,15 +25,14 @@ const Start = () => { useEffect(() => { notAllowedPages && goToStartPage(); - notSignUp && goToStartPage(); - accessToken && userData && goToHomePage(); + notSignUp ? goToStartPage() : goToHomePage(); }, []); return ( <>
- {!accessToken && id === '1' && ( + {id === '1' && (