From 9f3e473d31ea229cc05a5f4055d9a54ed58910d6 Mon Sep 17 00:00:00 2001 From: gyeongza Date: Tue, 25 Jun 2024 00:30:18 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=B0=B0=ED=8F=AC=EC=8B=9C=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EC=95=88=EB=90=98=EB=8A=94=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95=20(api=20route=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/token/route.ts | 35 ---------------------------------- src/features/auth/api/oauth.ts | 8 +++++--- 2 files changed, 5 insertions(+), 38 deletions(-) delete mode 100644 src/app/api/token/route.ts diff --git a/src/app/api/token/route.ts b/src/app/api/token/route.ts deleted file mode 100644 index c80dd98..0000000 --- a/src/app/api/token/route.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { API_BASE_URL } from '@/shared/api/constants'; -import axios, { AxiosError } from 'axios'; -import { cookies } from 'next/headers'; -import { NextRequest, NextResponse } from 'next/server'; - -export async function GET(req: NextRequest) { - const referer = process.env.NODE_ENV === 'development' ? 'http://localhost:3000' : API_BASE_URL; - const cookieStore = cookies(); - - try { - const url = new URL(req.url); - const code = url.searchParams.get('code'); - const response = await axios.get(`${API_BASE_URL}/api/v1/oauth/login/kakao?code=${code}`, { - headers: { - Referer: referer, - }, - }); - const jwt = response.headers?.['authorization'] as string; - - cookieStore.set('jwt_token', jwt, { httpOnly: true }); - - return NextResponse.json(jwt); - } catch (e) { - if (e instanceof AxiosError) { - console.error('Error:', e.response); - - return new Response(JSON.stringify({ error: e.message }), { - status: 500, - headers: { - 'Content-Type': 'application/json', - }, - }); - } - } -} diff --git a/src/features/auth/api/oauth.ts b/src/features/auth/api/oauth.ts index 4b7561e..10ef8e6 100644 --- a/src/features/auth/api/oauth.ts +++ b/src/features/auth/api/oauth.ts @@ -1,6 +1,7 @@ -import axios from 'axios'; import { ACCESS_TOKEN_LOCAL_STORAGE_KEY } from '../constants'; import LocalStorage from '@/shared/utils/localStorage'; +import instance from '@/shared/api/axios/instance'; +import { API_BASE_URL } from '@/shared/api/constants'; export const getAccessToken = () => LocalStorage.getItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY); @@ -17,9 +18,10 @@ export const logout = () => { export const getLoginToken = async (code: string) => { try { - const response = await axios.get(`/api/token?code=${code}`); + const response = await instance.get(`${API_BASE_URL}/api/v1/oauth/login/kakao?code=${code}`); + const jwt = response.headers?.['authorization'] as string; - saveAccessToken(response.data as string); + saveAccessToken(jwt); } catch (error) { alert('로그인 실패:'); console.error(error);