Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions src/app/(auth)/_api/auth/auth.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ export const useReissueMutation = () => {
export const useDeleteSessionMutation = () => {
return useMutation({
mutationFn: deleteClientSession,
onSuccess: () => {
clearClientSessionCache();
},
Comment on lines +33 to +38
Copy link
Member

Choose a reason for hiding this comment

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

P1: queryClient.clear()도 추가하는 것은 어떨까요?

그러면 흠,, onSettled에 넣어야 하려나 , , 성공했을 때만 지워도 될 것 같기도 하고 , ,

refs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

6c70ae3

queryClient.clear()도 추가했습니다~!

준환님 말씀처럼 onSettled로 항상 지워주기 보다는 에러가 발생했을 땐 세션이 남아있을 수도 있는 상황이라 토스트만 띄우는 편이 더 나을 거 같아여!!
그리고 전체 캐시를 다 날려서 로그인과 상관없는 다른 캐시 데이터들도 같이 초기화될 수 있을 것 같은데, 이 부분 추후에 얘기해봐도 좋을 것 같아요 👍🏻👍🏻

Copy link
Member

Choose a reason for hiding this comment

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

역시!

});
};
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