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);