-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 마이페이지 로그아웃 API 구현 (#86) #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
d07b33b
c20ae5e
1e25872
0291175
6c70ae3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 } | ||
| ); | ||
| } | ||
| }; |
| 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}> | ||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 고냥 참고만 해주십사! https://overlay-kit.slash.page/ko <- 애용하는 녀석인데 지금 이 코드도 잘 읽혀서 , , 나중에 참고만 해주셔용
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오!! 문서 쭉 읽어봤는데 확실히 상태 따로 선언 안 하고 바로 |
||
| )} | ||
| </li> | ||
| ))} | ||
| </VStack> | ||
| {/* TODO: 로그아웃시 나타날 모달 연결 */} | ||
| </> | ||
| ); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: queryClient.clear()도 추가하는 것은 어떨까요?
refs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6c70ae3
queryClient.clear()도 추가했습니다~!준환님 말씀처럼
onSettled로 항상 지워주기 보다는 에러가 발생했을 땐 세션이 남아있을 수도 있는 상황이라 토스트만 띄우는 편이 더 나을 거 같아여!!그리고 전체 캐시를 다 날려서 로그인과 상관없는 다른 캐시 데이터들도 같이 초기화될 수 있을 것 같은데, 이 부분 추후에 얘기해봐도 좋을 것 같아요 👍🏻👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
역시!