File tree Expand file tree Collapse file tree 2 files changed +35
-19
lines changed
Expand file tree Collapse file tree 2 files changed +35
-19
lines changed Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ import { useRouter } from 'next/navigation'
4+
5+ import { useMutation } from '@tanstack/react-query'
6+
7+ import { SignOut } from '@/services/auth/auth'
8+
9+ export const useSignOutMutation = ( ) => {
10+ const router = useRouter ( )
11+
12+ return useMutation ( {
13+ mutationFn : SignOut ,
14+ onSuccess : ( response : Response ) => {
15+ if ( ! response . ok ) {
16+ console . error ( 'Logout Failed' )
17+ alert ( '로그아웃 실패' )
18+ return
19+ }
20+
21+ const result = response . json ( )
22+ console . log ( '로그아웃 성공' , result )
23+
24+ alert ( '로그아웃 성공' )
25+ router . push ( `/sign-in` )
26+ } ,
27+ onError : ( error : unknown ) => {
28+ console . error ( 'Logout Error:' , error )
29+ alert ( '로그아웃 요청 중 오류가 발생했습니다' )
30+ } ,
31+ } )
32+ }
Original file line number Diff line number Diff line change 11'use client'
22
3- import { useRouter } from 'next/navigation '
3+ import { useSignOutMutation } from 'queries/useSignOut '
44
55export default function Home ( ) : JSX . Element {
6- const router = useRouter ( )
6+ const mutation = useSignOutMutation ( )
77
88 const handleLogout = async ( ) => {
9- try {
10- const response = await fetch ( `/api/auth/sign-out` , {
11- method : 'POST' ,
12- headers : { 'Content-Type' : 'application/json' } ,
13- } )
14- if ( ! response . ok ) {
15- console . error ( 'Logout failed' )
16- alert ( '로그아웃 실패 프록시' )
17- return
18- }
19- console . log ( 'Logout successful' )
20- alert ( '로그아웃 성공 프록시' )
21- router . push ( '/sign-in' )
22- } catch ( error ) {
23- console . error ( 'Logout error' , error )
24- alert ( '로그아웃 요청 중 오류 발생' )
25- }
9+ mutation . mutate ( )
2610 }
2711
2812 return (
You can’t perform that action at this time.
0 commit comments