Skip to content

Commit f992f37

Browse files
authored
Merge pull request #274 from code-zero-to-one/fix/QNRR-648/signup-flow-N-me-certify
fix : 회원가입 직후서버사이드 getUserProfile 404 문제해결
2 parents 1a28903 + ac5f98f commit f992f37

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1+
import { isAxiosError } from 'axios';
2+
import { redirect } from 'next/navigation';
13
import { axiosServerInstance } from '@/api/client/axios.server';
24
import { GetUserProfileResponse } from './types';
35

46
export 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
};

0 commit comments

Comments
 (0)