Skip to content

Commit

Permalink
Fix: signIn nav error
Browse files Browse the repository at this point in the history
  • Loading branch information
cuconveniencestore authored and hookor committed Jun 4, 2024
1 parent 3e9b6ad commit 9157c13
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
13 changes: 10 additions & 3 deletions src/components/start/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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');
Expand All @@ -40,20 +42,25 @@ 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 () => {
(await getMyInfo()) && navToHome();
};
return accessToken ? singIn() : navToSignUp();
}
accessToken && navToHome();
};

useEffect(() => {
verifyMembership();
verifyMembership(accessToken);
}, []);

return (
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useGetUserInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function useGetUserInfo(profileId?: string | number | undefined) {
res && setCachedUser(res.data);
return;
}
userData && setCachedUser(userData);

return userData && setCachedUser(userData);
};

useEffect(() => {
Expand Down
7 changes: 3 additions & 4 deletions src/pages/Page-Start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -25,15 +25,14 @@ const Start = () => {

useEffect(() => {
notAllowedPages && goToStartPage();
notSignUp && goToStartPage();
accessToken && userData && goToHomePage();
notSignUp ? goToStartPage() : goToHomePage();
}, []);

return (
<>
<SEOMeta pageData={id === '1' ? SEO_DATA.start : SEO_DATA.signUp} />
<div>
{!accessToken && id === '1' && (
{id === '1' && (
<Suspense>
<SignIn />
</Suspense>
Expand Down

0 comments on commit 9157c13

Please sign in to comment.