Skip to content

Commit 53a6205

Browse files
committed
fix: page view not corresponding to login state
1 parent e8aa63f commit 53a6205

31 files changed

+427
-220
lines changed

src/app/ErrorButton.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use client';
2+
3+
import { Button } from '@mantine/core';
4+
import { ReactNode } from 'react';
5+
6+
const ErrorButton = ({
7+
reset,
8+
errorMsg,
9+
navigate,
10+
}: {
11+
reset?: () => void;
12+
errorMsg: string | ReactNode;
13+
navigate?: () => void;
14+
}) => {
15+
return (
16+
<Button
17+
variant='default'
18+
size='md'
19+
mt='xl'
20+
className='control'
21+
onClick={() => {
22+
if (reset) reset();
23+
else if (navigate) navigate();
24+
}}
25+
mr='lg'
26+
>
27+
{errorMsg}
28+
</Button>
29+
);
30+
};
31+
32+
export default ErrorButton;

src/app/api/auth/[...nextauth]/auth.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export const {
5050
method: 'POST',
5151
}),
5252
);
53+
if (res?.httpStatus === 401) {
54+
return;
55+
}
5356

5457
if (res.id) {
5558
const userInfo = await Promise.resolve(
@@ -107,4 +110,8 @@ export const {
107110
return { ...session, token: token.accessToken };
108111
},
109112
},
113+
pages: {
114+
signIn: '/signin',
115+
error: '/signin',
116+
},
110117
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Box, Text } from '@mantine/core';
2+
3+
const AuthButton = ({ btnText, fn }: { btnText: string; fn: () => void }) => {
4+
return (
5+
<Box mt='lg'>
6+
<Text className='hvr txt' onClick={fn} size='sm' ta='center'>
7+
{btnText}
8+
</Text>
9+
</Box>
10+
);
11+
};
12+
export default AuthButton;

src/app/auth/components/LoginButton.tsx

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/app/auth/components/stories/LoginButton.stories.ts renamed to src/app/auth/components/stories/AuthButton.stories.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import LoginButton from '@/app/auth/components/LoginButton';
1+
import AuthButton from '@/app/auth/components/AuthButton';
22

33
export default {
44
title: '회원가입/로그인하러 가기',
5-
component: LoginButton,
5+
component: AuthButton,
66
args: { primary: true, label: '로그인하러 가기' },
77
tags: ['autodocs'],
88
};

src/app/auth/page.tsx

Lines changed: 6 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ import {
88
TextInput,
99
Title,
1010
} from '@mantine/core';
11-
import { notifications } from '@mantine/notifications';
12-
import { IconAt, IconCheck, IconPassword, IconUser } from '@tabler/icons-react';
11+
import { IconAt, IconPassword, IconUser } from '@tabler/icons-react';
1312
import { useRouter } from 'next/navigation';
1413
import { signIn, useSession } from 'next-auth/react';
1514
import { useState } from 'react';
1615
import styled from 'styled-components';
1716

18-
import { API_ROUTES, FAIL, SUCCESS } from '@/constants';
19-
import { getApiResponse } from '@/utils/get-api-response';
17+
import { signup } from '@/service/auth';
2018

21-
import LoginButton from './components/LoginButton';
19+
import AuthButton from './components/AuthButton';
2220

2321
export default function AuthPage() {
2422
const [nickname, setNickname] = useState('');
@@ -35,60 +33,6 @@ export default function AuthPage() {
3533
const regex =
3634
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}/g;
3735

38-
const postResponseFromApi = async () => {
39-
const res = await Promise.resolve(
40-
getApiResponse<undefined>({
41-
requestData: JSON.stringify({
42-
email: email,
43-
nickname: nickname,
44-
password: password,
45-
}),
46-
apiEndpoint: `${API_ROUTES.signup}`,
47-
method: 'POST',
48-
headers: {
49-
'Content-Type': 'application/json',
50-
},
51-
}),
52-
);
53-
if (res?.httpStatus === 409) {
54-
notifications.show({
55-
id: FAIL['409'].id,
56-
withCloseButton: true,
57-
autoClose: 6000,
58-
title: FAIL['409'].title,
59-
message: res.message,
60-
color: FAIL['409'].color,
61-
icon: <IconCheck className='icon' />,
62-
});
63-
64-
if (res.errorCode === 'NicknameAlreadyRegistered') {
65-
setNickname('');
66-
return;
67-
}
68-
if (res.errorCode === 'EmailAlreadyRegistered') {
69-
setEmail('');
70-
return;
71-
}
72-
}
73-
if (res?.httpStatus === 201) {
74-
notifications.show({
75-
id: SUCCESS.signup.id,
76-
withCloseButton: true,
77-
autoClose: 6000,
78-
title: SUCCESS.signup.title,
79-
message: res.message,
80-
color: SUCCESS.signup.color,
81-
icon: <IconCheck className='icon' />,
82-
});
83-
await signIn('credentials', {
84-
email,
85-
password,
86-
redirect: true,
87-
callbackUrl: '/',
88-
});
89-
}
90-
};
91-
9236
return (
9337
<PageWrap>
9438
<Box className='auth-box' p='xl'>
@@ -127,10 +71,7 @@ export default function AuthPage() {
12771
type='password'
12872
autoFocus={!password}
12973
withAsterisk={!password}
130-
description={
131-
// (!password || !password.match(regex)) &&
132-
'비밀번호는 영문, 숫자, 특수문자(@, $, !, %, *, ?, &) 하나 이상 조합해서 8자 이상 입력해주세요.'
133-
}
74+
description='비밀번호는 영문, 숫자, 특수문자(@, $, !, %, *, ?, &) 하나 이상 조합해서 8자 이상 입력해주세요.'
13475
placeholder='myPasswordCheck'
13576
onChange={(event) => setPassword(event.currentTarget.value)}
13677
leftSection={<IconPassword size={16} />}
@@ -175,14 +116,14 @@ export default function AuthPage() {
175116
) {
176117
return;
177118
}
178-
postResponseFromApi();
119+
signup({ email, nickname, password, setNickname, setEmail });
179120
}}
180121
>
181122
submit
182123
</Button>
183124
</div>
184125
<Divider my='xs' label='or' labelPosition='center' />
185-
<LoginButton />
126+
<AuthButton btnText='로그인 하러가기' fn={() => signIn()} />
186127
</Box>
187128
</Box>
188129
</PageWrap>

src/app/error.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { consoleLog } from '@/utils/console-log';
88

99
export default function ErrorPage({
1010
error,
11-
reset,
11+
// reset,
1212
}: Readonly<{
1313
error: Error & { digest?: string };
14-
reset: () => void;
14+
// reset: () => void;
1515
}>) {
1616
useEffect(() => {
1717
consoleLog('error.tsx', error);
@@ -21,7 +21,7 @@ export default function ErrorPage({
2121

2222
return (
2323
<main>
24-
<NotFound title={title} message={message} reset={reset} />
24+
<NotFound title={title} message={message} />
2525
</main>
2626
);
2727
}

src/app/mypage/@info/components/Profile.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import styled from 'styled-components';
1313

1414
import ProfileSkeleton from '@/components/shared/ProfileSkeleton';
1515

16-
import { API_ROUTES, FAIL, IS_PROD, SITE_ROUTES } from '@/constants';
16+
import { API_ROUTES, FAIL } from '@/constants';
1717
import { randomAvartars } from '@/utils/avatars';
1818
import { getApiResponse } from '@/utils/get-api-response';
1919

@@ -29,9 +29,9 @@ const UserData = () => {
2929
const [opened, { open, close }] = useDisclosure(false);
3030
const [modalContent, setModalContent] = useState('');
3131

32-
if (status === 'unauthenticated') {
33-
router.replace(IS_PROD ? SITE_ROUTES.signIn : SITE_ROUTES.signInDev);
34-
}
32+
// if (status === 'unauthenticated') {
33+
// router.replace(IS_PROD ? SITE_ROUTES.signIn : SITE_ROUTES.signInDev);
34+
// }
3535

3636
useEffect(() => {
3737
if (status === 'authenticated') {

src/app/mypage/@info/components/ProfileForm.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,6 @@ const ProfileForm = ({
9292

9393
return (
9494
<>
95-
{/* <TextInput
96-
value={nickname}
97-
label='닉네임'
98-
type='text'
99-
autoFocus={!nickname}
100-
withAsterisk={!nickname}
101-
description={
102-
nickname.length < 2 ? '닉네임은 2글자 이상이어야합니다.' : null
103-
}
104-
variant='filled'
105-
placeholder='myNickname'
106-
onChange={(event) => setNickname(event.currentTarget.value)}
107-
leftSection={<IconUser size={16} />}
108-
pb='md'
109-
/> */}
11095
<Textarea
11196
value={bio || ''}
11297
label='자기 소개'

src/app/mypage/@info/default.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
'use client';
22
import { signIn, useSession } from 'next-auth/react';
3-
4-
import ProfileSkeleton from '@/components/shared/ProfileSkeleton';
3+
import { useEffect } from 'react';
54

65
import UserData from './components/Profile';
76

87
export default function DefaultInfo() {
9-
const { status } = useSession();
8+
const { data: session, status } = useSession({
9+
required: true,
10+
onUnauthenticated() {
11+
return signIn();
12+
},
13+
});
14+
useEffect(() => {
15+
if (!session && status !== 'loading') {
16+
signIn();
17+
}
18+
// eslint-disable-next-line react-hooks/exhaustive-deps
19+
}, []);
1020

11-
if (status === 'unauthenticated') {
12-
return signIn();
13-
}
14-
if (status === 'loading') return <ProfileSkeleton />;
15-
if (status === 'authenticated') return <UserData />;
21+
return <UserData />;
1622
}

src/app/mypage/@info/page.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
'use client';
2-
import { signIn, useSession } from 'next-auth/react';
32

4-
import ProfileSkeleton from '@/components/shared/ProfileSkeleton';
3+
import DefaultInfo from './default';
54

6-
import UserData from './components/Profile';
7-
8-
export default function DefaultInfo() {
9-
const { status } = useSession();
10-
if (status === 'unauthenticated') {
11-
return signIn();
12-
}
13-
if (status === 'loading') return <ProfileSkeleton />;
14-
if (status === 'authenticated') return <UserData />;
5+
export default function MyInfo() {
6+
return <DefaultInfo />;
157
}

src/app/mypage/@roadmaps/created/CreatedRoadmaps.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ const CreatedRoadmapList = () => {
6161
queryFn: loadDataFromApi,
6262
});
6363

64-
if (status === 'unauthenticated') {
65-
signIn();
66-
}
64+
// if (status === 'unauthenticated') {
65+
// signIn();
66+
// }
6767
if (isLoading) {
6868
return <SkeletonCardsGrid />;
6969
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
'use client';
2-
import { signIn, useSession } from 'next-auth/react';
32

43
import MyRoadmapsTabs from '../Tabs';
54

65
export default function CreatedRoadmap() {
7-
const { status } = useSession();
8-
if (status === 'unauthenticated') {
9-
signIn();
10-
}
6+
// const { status } = useSession();
7+
// if (status === 'unauthenticated') {
8+
// signIn();
9+
// }
1110
return <MyRoadmapsTabs />;
1211
}

src/app/mypage/@roadmaps/in-progress/InProgressRoadmaps.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ const InProgressRoadmapList = () => {
5555
};
5656
};
5757

58-
if (status === 'unauthenticated') {
59-
signIn();
60-
}
58+
// if (status === 'unauthenticated') {
59+
// signIn();
60+
// }
6161

6262
const { data, isLoading, isError, isSuccess } = useQuery({
6363
queryKey: [`post-inprogress-${nickname}`],
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
'use client';
2-
import { signIn, useSession } from 'next-auth/react';
32

43
import MyRoadmapsTabs from '../Tabs';
54

65
export default function InProgressRoadmap() {
7-
const { status } = useSession();
8-
if (status === 'unauthenticated') {
9-
signIn();
10-
}
6+
// const { status } = useSession();
7+
// if (status === 'unauthenticated') {
8+
// signIn();
9+
// }
1110

1211
return <MyRoadmapsTabs />;
1312
}

0 commit comments

Comments
 (0)