Skip to content

Commit cc6c1bc

Browse files
[FE-245] feat: 탈퇴하기 ProtectedRoute 적용
1 parent 653da9f commit cc6c1bc

4 files changed

Lines changed: 49 additions & 7 deletions

File tree

src/pages/Setting/Withdraw/Withdraw.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ const Withdraw = () => {
4343
<section id="withdraw-navigate-button" className="mt-[180px] px-6">
4444
<Button
4545
property="danger"
46-
onClick={() =>
47-
navigate('/setting/withdraw/check', { state, replace: true })
48-
}
46+
onClick={() => navigate('/setting/withdraw/check', { state })}
4947
>
5048
탈퇴하기
5149
</Button>

src/react-query/hooks/useUser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export const useUser = () => {
1515
refetchOnMount: false,
1616
refetchOnReconnect: false,
1717
refetchOnWindowFocus: false,
18+
onError: () => {
19+
queryClient.setQueriesData([QUERY_KEYS.user], null)
20+
},
1821
})
1922

2023
const logoutUser = async () => {

src/routes/protectedRoute.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const ProtectedRoute = ({ children, route }: RouteProps) => {
4343
)
4444
}
4545

46-
if (!user && route?.indexOf('myrecord')) {
46+
if (!user && route?.indexOf('myrecord') !== -1) {
4747
return (
4848
<Alert
4949
visible={true}
@@ -64,6 +64,26 @@ const ProtectedRoute = ({ children, route }: RouteProps) => {
6464
)
6565
}
6666

67+
if (!user && route?.indexOf('withdraw') !== -1) {
68+
return (
69+
<Alert
70+
visible={true}
71+
mainMessage={
72+
<div className="text-base font-semibold leading-6">
73+
비회원은 계정을
74+
<br />
75+
<span className="text-sub-1">탈퇴</span> 할 수 없어요
76+
</div>
77+
}
78+
cancelMessage="닫기"
79+
confirmMessage="로그인"
80+
onClose={() => navigate('/')}
81+
onCancel={() => navigate('/')}
82+
onConfirm={() => redirectPage('/setting')}
83+
/>
84+
)
85+
}
86+
6787
return children
6888
}
6989

src/routes/router.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,30 @@ const router = createBrowserRouter([
111111
{
112112
path: 'withdraw',
113113
children: [
114-
{ index: true, element: <Withdraw /> },
115-
{ path: 'check', element: <CheckedNicknameBeforeWithDraw /> },
116-
{ path: 'complete', element: <CompletedWithdraw /> },
114+
{
115+
index: true,
116+
element: (
117+
<ProtectedRoute route={'/setting/withdraw'}>
118+
<Withdraw />
119+
</ProtectedRoute>
120+
),
121+
},
122+
{
123+
path: 'check',
124+
element: (
125+
<ProtectedRoute route={'/setting/withdraw/check'}>
126+
<CheckedNicknameBeforeWithDraw />
127+
</ProtectedRoute>
128+
),
129+
},
130+
{
131+
path: 'complete',
132+
element: (
133+
<ProtectedRoute route={'/setting/withdraw/complete'}>
134+
<CompletedWithdraw />
135+
</ProtectedRoute>
136+
),
137+
},
117138
],
118139
},
119140
],

0 commit comments

Comments
 (0)