File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
app/api/auth/clear-session Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 1+ import { cookies } from 'next/headers' ;
2+ import { NextRequest , NextResponse } from 'next/server' ;
3+
4+ export async function GET ( request : NextRequest ) {
5+ const searchParams = request . nextUrl . searchParams ;
6+ const redirectTo = searchParams . get ( 'redirect' ) || '/login' ;
7+
8+ // 쿠키 삭제
9+ const cookieStore = await cookies ( ) ;
10+ cookieStore . delete ( 'accessToken' ) ;
11+ cookieStore . delete ( 'memberId' ) ;
12+ cookieStore . delete ( 'socialImageURL' ) ;
13+
14+ // 리다이렉트
15+ return NextResponse . redirect ( new URL ( redirectTo , request . url ) ) ;
16+ }
Original file line number Diff line number Diff line change 1+ import { isAxiosError } from 'axios' ;
2+ import { redirect } from 'next/navigation' ;
13import { axiosServerInstance } from '@/api/client/axios.server' ;
24import { GetUserProfileResponse } from './types' ;
35
46export const getUserProfileInServer = async (
57 memberId : number ,
68) : Promise < GetUserProfileResponse > => {
7- const res = await axiosServerInstance . get ( `/members/${ memberId } /profile` ) ;
9+ try {
10+ const res = await axiosServerInstance . get ( `/members/${ memberId } /profile` ) ;
811
9- return res . data . content ;
12+ return res . data . content ;
13+ } catch ( error ) {
14+ // 회원가입 직후 프로필이 아직 생성되지 않았거나 인증 문제인 경우
15+ // Route Handler로 리다이렉트하여 쿠키 삭제 후 로그인 페이지로 이동
16+ if ( isAxiosError ( error ) ) {
17+ const status = error . response ?. status ;
18+
19+ if ( status === 404 || status === 401 || status === 403 ) {
20+ redirect ( '/api/auth/clear-session?redirect=/login' ) ;
21+ }
22+ }
23+
24+ // 예상치 못한 에러는 다시 throw
25+ throw error ;
26+ }
1027} ;
You can’t perform that action at this time.
0 commit comments