File tree Expand file tree Collapse file tree 2 files changed +48
-10
lines changed
Expand file tree Collapse file tree 2 files changed +48
-10
lines changed Original file line number Diff line number Diff line change 1+ import { NextResponse } from 'next/server' ;
2+
3+ export const POST = async ( ) : Promise < NextResponse > => {
4+ try {
5+ const res = NextResponse . json ( { success : true , message : '로그아웃 성공' } ) ;
6+
7+ res . cookies . set ( 'accessToken' , '' , {
8+ httpOnly : true ,
9+ secure : true ,
10+ sameSite : 'strict' ,
11+ path : '/' ,
12+ maxAge : 0 ,
13+ } ) ;
14+
15+ res . cookies . set ( 'refreshToken' , '' , {
16+ httpOnly : true ,
17+ secure : true ,
18+ sameSite : 'strict' ,
19+ path : '/' ,
20+ maxAge : 0 ,
21+ } ) ;
22+
23+ return res ;
24+ } catch ( error : any ) {
25+ console . error ( '로그아웃 처리 중 오류 발생:' , error ) ;
26+ return NextResponse . json (
27+ { success : false , message : '서버 오류로 로그아웃 실패' } ,
28+ { status : 500 }
29+ ) ;
30+ }
31+ } ;
Original file line number Diff line number Diff line change 33import { useRouter } from 'next/navigation'
44
55import axios from 'axios'
6-
6+ import { signOut } from '@/services/auth/auth'
77import { useAuthStore } from '@/stores/useAuthStore'
88
99export default function Home ( ) : JSX . Element {
1010 const { logout } = useAuthStore ( )
11+
1112 const router = useRouter ( )
1213
1314 const handleLogout = async ( ) => {
1415 try {
15- await axios . post ( '/v1/auth/logout' , { } , { withCredentials : true } )
16- console . log ( '서버 로그아웃 성공' )
17-
18- logout ( )
19-
16+ const response = await fetch ( `/api/auth/sign-out` , {
17+ method : 'POST' ,
18+ headers : { 'Content-Type' : 'application/json' } ,
19+ } )
20+ if ( ! response . ok ) {
21+ const errorResult = await response . json ( )
22+ console . error ( 'Logout failed' )
23+ alert ( '로그아웃 실패 프록시' )
24+ return
25+ }
26+ console . log ( 'Logout successful' )
27+ alert ( '로그아웃 성공 프록시' )
2028 router . push ( '/sign-in' )
21- console . log ( '로그아웃 성공' )
22- } catch ( error ) {
23- console . error ( '로그아웃 실패:' , error )
24- alert ( '로그아웃에 실패했습니다.' )
29+ } catch ( error ) {
30+ console . error ( 'Logout error' , error )
31+ alert ( '로그아웃 요청 중 오류 발생' )
2532 }
2633 }
2734
You can’t perform that action at this time.
0 commit comments