Skip to content

Commit 4662e18

Browse files
authored
Merge pull request #92 from YAPP-Github/feature/PRODUCT-188
feat: 마이페이지 로그아웃 API 구현 (#86)
2 parents ee8d451 + 6c70ae3 commit 4662e18

File tree

5 files changed

+90
-5
lines changed

5 files changed

+90
-5
lines changed

src/app/(auth)/_api/auth/auth.queries.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ export const useReissueMutation = () => {
2828
};
2929

3030
export const useDeleteSessionMutation = () => {
31+
const queryClient = useQueryClient();
32+
3133
return useMutation({
3234
mutationFn: deleteClientSession,
35+
onSuccess: () => {
36+
clearClientSessionCache();
37+
queryClient.clear();
38+
},
3339
});
3440
};

src/app/api/auth/logout/route.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { NextResponse } from "next/server";
2+
3+
import { getSessionFromServer } from "@/lib/session/serverSession";
4+
5+
export const DELETE = async () => {
6+
try {
7+
const session = await getSessionFromServer();
8+
if (!session.isLoggedIn) {
9+
return NextResponse.json(
10+
{ errorMessage: "세션이 존재하지 않습니다." },
11+
{ status: 401 }
12+
);
13+
}
14+
15+
await session.destroy();
16+
17+
return NextResponse.json({ message: "로그아웃 완료" }, { status: 200 });
18+
} catch (error) {
19+
console.error("로그아웃 중 에러:", error);
20+
return NextResponse.json(
21+
{ errorMessage: "로그아웃 처리 중 오류가 발생했습니다." },
22+
{ status: 500 }
23+
);
24+
}
25+
};

src/app/member/profile/_components/MenuList/MenuList.css.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ export const menuItem = style({
1414
...typography.body1Sb,
1515
color: semantic.text.normal,
1616
});
17+
18+
export const modalButton = style({
19+
flex: 1,
20+
});
Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
"use client";
22

3+
import * as AlertDialog from "@radix-ui/react-alert-dialog";
34
import Link from "next/link";
5+
import { useRouter } from "next/navigation";
46

7+
import { useDeleteSessionMutation } from "@/app/(auth)/_api/auth/auth.queries";
8+
import { AlertModal } from "@/components/ui/AlertModal";
9+
import { Button } from "@/components/ui/Button";
510
import { VStack } from "@/components/ui/Stack";
611

712
import { MENU_LIST } from "../../_constants";
813
import * as styles from "./MenuList.css";
914

1015
export const MenuList = () => {
16+
const router = useRouter();
17+
const { mutate: logout } = useDeleteSessionMutation();
18+
19+
const handleLogout = () => {
20+
logout(undefined, {
21+
onSuccess: () => {
22+
// TODO: Toast 띄우기
23+
router.replace("/");
24+
},
25+
onError: error => {
26+
// TODO: Toast 띄우기
27+
console.error("로그아웃 실패", error);
28+
},
29+
});
30+
};
31+
1132
return (
1233
<>
1334
<VStack as='ul' gap={8} className={styles.wrapper}>
@@ -18,14 +39,43 @@ export const MenuList = () => {
1839
{menu.label}
1940
</Link>
2041
) : (
21-
<button type='button' className={styles.menuItem}>
22-
{menu.label}
23-
</button>
42+
<AlertModal
43+
title='로그아웃하시나요?'
44+
trigger={
45+
<button type='button' className={styles.menuItem}>
46+
로그아웃
47+
</button>
48+
}
49+
footer={
50+
<>
51+
<AlertDialog.Cancel asChild>
52+
<Button
53+
variant='assistive'
54+
size='large'
55+
className={styles.modalButton}
56+
style={{ borderRadius: "0 0 0 1.2rem" }}
57+
>
58+
취소
59+
</Button>
60+
</AlertDialog.Cancel>
61+
<AlertDialog.Action asChild>
62+
<Button
63+
variant='primary'
64+
size='large'
65+
onClick={handleLogout}
66+
className={styles.modalButton}
67+
style={{ borderRadius: "0 0 1.2rem" }}
68+
>
69+
확인
70+
</Button>
71+
</AlertDialog.Action>
72+
</>
73+
}
74+
/>
2475
)}
2576
</li>
2677
))}
2778
</VStack>
28-
{/* TODO: 로그아웃시 나타날 모달 연결 */}
2979
</>
3080
);
3181
};

src/components/ui/AlertModal/AlertModal.css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const content = style({
2020
transform: "translate(-50%, -50%)",
2121
width: "min(30rem, 90vw)",
2222
background: semantic.background.white,
23-
borderRadius: radius[120],
23+
borderRadius: radius[160],
2424
zIndex: zIndex.modal,
2525
});
2626

0 commit comments

Comments
 (0)