|
|
@@ -1,7 +1,7 @@
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
|
-import { ResultDto } from '@/types/response/common';
|
|
|
import { LoginResponse } from '@/types/response/auth';
|
|
|
-import { fetchJson } from '@/lib/utils/server';
|
|
|
+
|
|
|
+const API_URL = process.env.API_URL;
|
|
|
|
|
|
export async function POST(request: NextRequest)
|
|
|
{
|
|
|
@@ -15,15 +15,19 @@ export async function POST(request: NextRequest)
|
|
|
return NextResponse.redirect(url);
|
|
|
}
|
|
|
|
|
|
- // 백엔드 google-login API 호출
|
|
|
- const res: ResultDto = await fetchJson('/api/auth/google-login', {
|
|
|
+ // 백엔드 google-login API 직접 호출
|
|
|
+ const res = await fetch(`${API_URL}/api/auth/google-login`, {
|
|
|
method: 'POST',
|
|
|
- body: JSON.stringify({ credential })
|
|
|
+ headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
|
|
|
+ body: JSON.stringify({ credential }),
|
|
|
+ cache: 'no-store'
|
|
|
});
|
|
|
|
|
|
- if (res.success && res.data) {
|
|
|
- const data = res.data as LoginResponse;
|
|
|
- const response = NextResponse.redirect(new URL('/auth/login/google/complete', request.url));
|
|
|
+ const json = await res.json();
|
|
|
+
|
|
|
+ if (json.success && json.data) {
|
|
|
+ const data = json.data as LoginResponse;
|
|
|
+ const response = NextResponse.redirect(new URL('/login/google/complete', request.url));
|
|
|
const cookieOptions = { httpOnly: true, path: '/' };
|
|
|
response.cookies.set('accessToken', data.accessToken, cookieOptions);
|
|
|
response.cookies.set('refreshToken', data.refreshToken, cookieOptions);
|
|
|
@@ -32,6 +36,6 @@ export async function POST(request: NextRequest)
|
|
|
|
|
|
// 실패 시 로그인 페이지로 리다이렉트
|
|
|
const url = new URL('/login', request.url);
|
|
|
- url.searchParams.set('error', res.message || 'Google 로그인에 실패했습니다.');
|
|
|
+ url.searchParams.set('error', json.message || 'Google 로그인에 실패했습니다.');
|
|
|
return NextResponse.redirect(url);
|
|
|
}
|