Skip to content

Commit

Permalink
fix(login): 로그인 로직 오류 수정 (#82)
Browse files Browse the repository at this point in the history
* fix

* fix

* fix
  • Loading branch information
Collection50 authored Sep 7, 2024
1 parent 16c94d4 commit 421c0d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 9 additions & 7 deletions src/app/AuthRedirect.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { cookies } from 'next/headers';
'use client';

import { ACCESS_TOKEN, JOB_SELECTION, REFRESH_TOKEN } from './login/constants/token';
import { redirect } from 'next/navigation';
import type { StrictPropsWithChildren } from '@/types';
import { deleteCookie, getCookie } from 'cookies-next';

export default async function AuthRedirect({ children }: StrictPropsWithChildren) {
const accessToken = cookies().get(ACCESS_TOKEN)?.value;
const isJobSelection = cookies().get(JOB_SELECTION)?.value;
export default function AuthRedirect({ children }: StrictPropsWithChildren) {
const accessToken = getCookie(ACCESS_TOKEN) as string;
const isJobSelection = getCookie(JOB_SELECTION) as string;

if (!accessToken || !isJobSelection) {
cookies().delete(ACCESS_TOKEN);
cookies().delete(REFRESH_TOKEN);
cookies().delete(JOB_SELECTION);
deleteCookie(ACCESS_TOKEN);
deleteCookie(REFRESH_TOKEN);
deleteCookie(JOB_SELECTION);
redirect('/login');
}

Expand Down
5 changes: 2 additions & 3 deletions src/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import { useFunnel } from '@/system/components/Funnel/useFunnel';
import { getCookie } from 'cookies-next';
import { Login } from './components/Login';
import Select from './components/Select';
import { ACCESS_TOKEN, JOB_SELECTION, SELECT } from './constants/token';
import { JOB_SELECTION, SELECT } from './constants/token';

export default function Page() {
const Funnel = useFunnel(['login', 'select'] as const, { initialStep: 'login', stepQueryKey: 'auth' });
const isSelectJob = getCookie(JOB_SELECTION) === SELECT;
const accessToken = getCookie(ACCESS_TOKEN);

return (
<Funnel mode="wait">
<Funnel.Step name="login">
<Redirect condition={accessToken != null && !isSelectJob} to="/login?auth=select">
<Redirect condition={!isSelectJob} to="/login?auth=select">
<Login />
</Redirect>
</Funnel.Step>
Expand Down

0 comments on commit 421c0d3

Please sign in to comment.