Skip to content

Commit acda414

Browse files
authored
Merge pull request #94 from GDGoCINHA/develop
Fix: 기존 인증 URL을 프록시 URL로 변경하여 로그인 API 호출 방식 수정
2 parents 3ec5913 + 7f02ecd commit acda414

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

src/app/api/signin/route.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import axios from 'axios';
2+
import { NextResponse } from 'next/server';
3+
4+
const ORIGINAL_AUTH_URL = 'https://gdgocinha.site/auth';
5+
6+
export async function POST(request) {
7+
try {
8+
// 클라이언트로부터 받은 요청 데이터 추출
9+
const { email, password } = await request.json();
10+
11+
// gdgocinha.site/auth/login으로 요청 전달
12+
const response = await axios.post(
13+
`${ORIGINAL_AUTH_URL}/login`,
14+
{ email, password },
15+
{
16+
headers: { 'Content-Type': 'application/json' },
17+
withCredentials: true,
18+
}
19+
);
20+
21+
// 원본 응답 데이터
22+
const data = response.data;
23+
24+
// 쿠키 처리를 위한 응답 생성
25+
const nextResponse = NextResponse.json(data, {
26+
status: response.status,
27+
statusText: response.statusText,
28+
});
29+
30+
// 원본 응답의 쿠키가 있으면 추출하여 현재 도메인에 설정
31+
const cookies = response.headers['set-cookie'];
32+
if (cookies) {
33+
cookies.forEach(cookie => {
34+
// 쿠키 문자열에서 이름과 값 부분만 추출
35+
const cookieParts = cookie.split(';')[0].split('=');
36+
const cookieName = cookieParts[0];
37+
const cookieValue = cookieParts.slice(1).join('=');
38+
39+
// 추출한 쿠키를 현재 도메인에 설정
40+
nextResponse.cookies.set(cookieName, cookieValue, {
41+
path: '/',
42+
httpOnly: true,
43+
secure: process.env.NODE_ENV === 'production',
44+
sameSite: 'strict',
45+
});
46+
});
47+
}
48+
49+
return nextResponse;
50+
} catch (error) {
51+
console.error('로그인 프록시 오류:', error);
52+
return NextResponse.json(
53+
{ error: '로그인 처리 중 오류가 발생했습니다.' },
54+
{ status: error.response?.status || 500 }
55+
);
56+
}
57+
}

src/app/auth/signin/custom/CustomAuthApi.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
'use client';
22
import axios from 'axios';
33

4-
const CUSTOM_AUTH_URL = 'https://gdgocinha.site/auth';
4+
// 기존 직접 요청 URL
5+
// const CUSTOM_AUTH_URL = 'https://gdgocinha.site/auth';
6+
7+
// 새로운 프록시 URL (상대 경로 사용)
8+
const PROXY_AUTH_URL = '/api/signin';
59

610
export const login = async (email, password) => {
711
try {
812
const response = await axios.post(
9-
`${CUSTOM_AUTH_URL}/login`,
13+
PROXY_AUTH_URL,
1014
{ email, password },
1115
{
1216
headers: { 'Content-Type': 'application/json' },

0 commit comments

Comments
 (0)