Skip to content

Commit abb0161

Browse files
committed
fix: 알바폼 상세 조회 route > 토큰 여부에 따른 응답 수정
1 parent 43f4d1d commit abb0161

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/app/api/forms/[formId]/route.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@ import { cookies } from "next/headers";
33
import { NextRequest, NextResponse } from "next/server";
44
import apiClient from "@/lib/apiClient";
55

6-
// 알바폼 상세 조회(로그인 안한 유저도 조회 가능)
6+
// 알바폼 상세 조회(로그인 여부에 따라 다른 응답)
77
export async function GET(req: NextRequest, { params }: { params: { formId: string } }) {
88
try {
9-
const response = await apiClient.get(`/forms/${params.formId}`);
9+
const accessToken = cookies().get("accessToken")?.value;
1010

11+
// 로그인한 유저의 경우 토큰과 함께 요청
12+
if (accessToken) {
13+
const response = await apiClient.get(`/forms/${params.formId}`, {
14+
headers: {
15+
Authorization: `Bearer ${accessToken}`,
16+
},
17+
});
18+
return NextResponse.json(response.data);
19+
}
20+
21+
// 로그인하지 않은 유저의 경우 토큰 없이 요청
22+
const response = await apiClient.get(`/forms/${params.formId}`);
1123
return NextResponse.json(response.data);
1224
} catch (error: unknown) {
1325
if (error instanceof AxiosError) {

0 commit comments

Comments
 (0)