Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/app/(auth)/_api/auth/auth.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ export const useReissueMutation = () => {
};

export const useDeleteSessionMutation = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: deleteClientSession,
onSuccess: () => {
clearClientSessionCache();
queryClient.clear();
},
});
};
25 changes: 25 additions & 0 deletions src/app/api/auth/logout/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { NextResponse } from "next/server";

import { getSessionFromServer } from "@/lib/session/serverSession";

export const DELETE = async () => {
try {
const session = await getSessionFromServer();
if (!session.isLoggedIn) {
return NextResponse.json(
{ errorMessage: "세션이 존재하지 않습니다." },
{ status: 401 }
);
}

await session.destroy();

return NextResponse.json({ message: "로그아웃 완료" }, { status: 200 });
} catch (error) {
console.error("로그아웃 중 에러:", error);
return NextResponse.json(
{ errorMessage: "로그아웃 처리 중 오류가 발생했습니다." },
{ status: 500 }
);
}
};
4 changes: 4 additions & 0 deletions src/app/member/profile/_components/MenuList/MenuList.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ export const menuItem = style({
...typography.body1Sb,
color: semantic.text.normal,
});

export const modalButton = style({
flex: 1,
});
58 changes: 54 additions & 4 deletions src/app/member/profile/_components/MenuList/MenuList.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
"use client";

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

import { useDeleteSessionMutation } from "@/app/(auth)/_api/auth/auth.queries";
import { AlertModal } from "@/components/ui/AlertModal";
import { Button } from "@/components/ui/Button";
import { VStack } from "@/components/ui/Stack";

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

export const MenuList = () => {
const router = useRouter();
const { mutate: logout } = useDeleteSessionMutation();

const handleLogout = () => {
logout(undefined, {
onSuccess: () => {
// TODO: Toast 띄우기
router.replace("/");
},
onError: error => {
// TODO: Toast 띄우기
console.error("로그아웃 실패", error);
},
});
};

return (
<>
<VStack as='ul' gap={8} className={styles.wrapper}>
Expand All @@ -18,14 +39,43 @@ export const MenuList = () => {
{menu.label}
</Link>
) : (
<button type='button' className={styles.menuItem}>
{menu.label}
</button>
<AlertModal
title='로그아웃하시나요?'
trigger={
<button type='button' className={styles.menuItem}>
로그아웃
</button>
}
footer={
<>
<AlertDialog.Cancel asChild>
<Button
variant='assistive'
size='large'
className={styles.modalButton}
style={{ borderRadius: "0 0 0 1.2rem" }}
>
취소
</Button>
</AlertDialog.Cancel>
<AlertDialog.Action asChild>
<Button
variant='primary'
size='large'
onClick={handleLogout}
className={styles.modalButton}
style={{ borderRadius: "0 0 1.2rem" }}
>
확인
</Button>
</AlertDialog.Action>
</>
}
/>
Comment on lines +42 to +74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고냥 참고만 해주십사!

https://overlay-kit.slash.page/ko <- 애용하는 녀석인데 지금 이 코드도 잘 읽혀서 , , 나중에 참고만 해주셔용

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오!! 문서 쭉 읽어봤는데 확실히 상태 따로 선언 안 하고 바로 overlay.open으로 관리할 수 있는 게 깔끔하네요@@!!
버튼 클릭 시 그 안에 들어갈 UI만 넘기면 돼서 모달같은 오버레이 로직이 훨씬 단순해질 것 같아요..!
시간날 때 리팩토링 해볼게요!!👍🏻 감사함돠 🙇🏻‍♀️

)}
</li>
))}
</VStack>
{/* TODO: 로그아웃시 나타날 모달 연결 */}
</>
);
};
2 changes: 1 addition & 1 deletion src/components/ui/AlertModal/AlertModal.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const content = style({
transform: "translate(-50%, -50%)",
width: "min(30rem, 90vw)",
background: semantic.background.white,
borderRadius: radius[120],
borderRadius: radius[160],
zIndex: zIndex.modal,
});

Expand Down