From 7a13911b0d47abeb09d681e63c4e9f8a5de8b36e Mon Sep 17 00:00:00 2001 From: yyezzzy Date: Fri, 6 Dec 2024 15:38:49 +0900 Subject: [PATCH 1/4] =?UTF-8?q?bug:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EA=B0=84=ED=8E=B8=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(auth)/login/page.tsx | 8 ++- src/app/(auth)/signup/applicant/page.tsx | 4 +- src/app/(auth)/signup/owner/page.tsx | 4 +- src/app/api/oauth/callback/google/route.ts | 4 +- src/app/api/oauth/callback/kakao/route.ts | 66 ++++++++++----------- src/app/api/oauth/login/[provider]/route.ts | 3 +- src/types/oauth/oauth.d.ts | 22 +++++++ src/types/oauth/oauthReq.ts | 11 ---- 8 files changed, 66 insertions(+), 56 deletions(-) create mode 100644 src/types/oauth/oauth.d.ts delete mode 100644 src/types/oauth/oauthReq.ts diff --git a/src/app/(auth)/login/page.tsx b/src/app/(auth)/login/page.tsx index 10552b0a..b390f000 100644 --- a/src/app/(auth)/login/page.tsx +++ b/src/app/(auth)/login/page.tsx @@ -65,12 +65,16 @@ export default function LoginPage() {
구글 로그인 카카오 로그인 diff --git a/src/app/(auth)/signup/applicant/page.tsx b/src/app/(auth)/signup/applicant/page.tsx index 84941699..f6ea1129 100644 --- a/src/app/(auth)/signup/applicant/page.tsx +++ b/src/app/(auth)/signup/applicant/page.tsx @@ -109,14 +109,14 @@ export default function ApplicantSignupPage() {
구글 회원가입 카카오 회원가입 diff --git a/src/app/(auth)/signup/owner/page.tsx b/src/app/(auth)/signup/owner/page.tsx index 5840c6c5..322e29a5 100644 --- a/src/app/(auth)/signup/owner/page.tsx +++ b/src/app/(auth)/signup/owner/page.tsx @@ -131,14 +131,14 @@ export default function OwnerSignupPage() {
구글 회원가입 카카오 회원가입 diff --git a/src/app/api/oauth/callback/google/route.ts b/src/app/api/oauth/callback/google/route.ts index 3fa90861..e51adc5e 100644 --- a/src/app/api/oauth/callback/google/route.ts +++ b/src/app/api/oauth/callback/google/route.ts @@ -1,8 +1,8 @@ import { NextRequest, NextResponse } from "next/server"; import axios from "axios"; import { decodeJwt } from "@/middleware"; -import { OauthUser } from "@/types/oauth/oauthReq"; import apiClient from "@/lib/apiClient"; +import { OauthSignupUser } from "@/types/oauth/oauth"; export const GET = async (req: NextRequest) => { const searchParams = req.nextUrl.searchParams; @@ -57,7 +57,7 @@ export const GET = async (req: NextRequest) => { return NextResponse.json({ message: "Invalid ID token" }, { status: 400 }); } - const googleUser: OauthUser = { + const googleUser: OauthSignupUser = { role: role, name: decodedIdToken.name, token: id_token, diff --git a/src/app/api/oauth/callback/kakao/route.ts b/src/app/api/oauth/callback/kakao/route.ts index 1694d590..fdcc8f3e 100644 --- a/src/app/api/oauth/callback/kakao/route.ts +++ b/src/app/api/oauth/callback/kakao/route.ts @@ -1,6 +1,6 @@ import { NextRequest, NextResponse } from "next/server"; -import { OauthUser } from "@/types/oauth/oauthReq"; -import apiClient from "@/lib/apiClient"; +import { OauthLoginUser, OauthResponse, OauthSignupUser } from "@/types/oauth/oauth"; +import axios from "axios"; export const GET = async (req: NextRequest) => { const searchParams = req.nextUrl.searchParams; @@ -22,49 +22,43 @@ export const GET = async (req: NextRequest) => { console.error("Failed to parse state:", error); return NextResponse.json({ message: "Invalid state format" }, { status: 400 }); } - const { provider, role } = parsedState; + console.log("parsedState:", parsedState); - const clientId = process.env.NEXT_PUBLIC_KAKAO_REST_API_KEY; + const { provider, action, role } = parsedState; const redirectUri = process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URI; - if (!clientId || !redirectUri) { + if (!redirectUri) { return NextResponse.json({ message: "Environment variables not set" }, { status: 500 }); } - const kakaoUser: OauthUser = { - role: role, - name: "", // 기본값 설정 (빈 문자열) - token: code, // 인가코드 그대로 전달 - redirectUri: redirectUri, - }; - try { - // 인가코드를 포함한 데이터를 백엔드로 전달 - const kakaoSignupResponse = await apiClient.post(`/oauth/sign-up/${provider}`, kakaoUser); - console.log("카카오 회원가입 성공:", kakaoSignupResponse.data); + if (action === "signup") { + // 회원가입 로직 + const signupUser: OauthSignupUser = { + role: role || "user", // role 값이 없으면 기본값으로 "user" 설정 + name: "", // 회원가입 시 이름은 추후 API로 받아오거나 기본값으로 처리 + token: code, // 인가코드 전달 + redirectUri, + }; + console.log("회원가입 시도:", signupUser); - // 사용자 정보를 클라이언트에 반환 - // return NextResponse.json(kakaoSignupResponse.data); - } catch (error: any) { - // 에러 타입 명시 - console.error("카카오 회원가입 에러:", error.response?.data || error.message); + const signupResponse = await axios.post(`/api/oauth/signup`, { provider, ...signupUser }); + console.log("회원가입 성공:", signupResponse.data); + } else if (action === "login") { + // 로그인 로직 + const loginUser: OauthLoginUser = { + token: code, + redirectUri, + }; + console.log("로그인 시도", loginUser); - // return NextResponse.json({ message: error.response?.data || "Error during Kakao signup" }, { status: 500 }); - } - - try { - // 사용자 정보를 클라이언트에 반환 - const response = NextResponse.redirect("http://localhost:3000"); - response.cookies.set("user", JSON.stringify(kakaoUser), { - httpOnly: true, - secure: process.env.NODE_ENV === "production", - sameSite: "strict", - maxAge: 60 * 60 * 24, // 1일 - path: "/", - }); - return response; + const loginResponse = await axios.post(`/api/oauth/login/${provider}`, { provider, ...loginUser }); + console.log("로그인 성공:", loginResponse.data); + } else { + return NextResponse.json({ message: "Invalid action" }, { status: 400 }); + } } catch (error: any) { - console.error("카카오 회원가입 에러:", error.response?.data || error.message); - return NextResponse.json({ message: error.response?.data || "서버에러" }, { status: 500 }); + console.error(`${provider} ${action} 에러:`, error); + return NextResponse.json({ message: error.response?.data || "Internal Server Error" }, { status: 500 }); } }; diff --git a/src/app/api/oauth/login/[provider]/route.ts b/src/app/api/oauth/login/[provider]/route.ts index b766e3ea..23be7ad0 100644 --- a/src/app/api/oauth/login/[provider]/route.ts +++ b/src/app/api/oauth/login/[provider]/route.ts @@ -6,6 +6,7 @@ import apiClient from "@/lib/apiClient"; // OAuth 로그인 API export async function POST(request: Request, { params }: { params: { provider: string } }) { try { + console.log("/api/oauth/login"); const provider = params.provider; // provider 유효성 검사 @@ -15,7 +16,7 @@ export async function POST(request: Request, { params }: { params: { provider: s // 요청 본문 파싱 const body = await request.json(); - + console.log("Received body:", body); // 요청 본문 로그 출력 // OAuth 로그인 요청 const response = await apiClient.post(`/oauth/sign-in/${provider}`, body); diff --git a/src/types/oauth/oauth.d.ts b/src/types/oauth/oauth.d.ts new file mode 100644 index 00000000..ca4ca5a8 --- /dev/null +++ b/src/types/oauth/oauth.d.ts @@ -0,0 +1,22 @@ +export interface OauthSignupUser { + location?: string; + phoneNumber?: string; + storePhoneNumber?: string; + storeName?: string; + role: string; + nickname?: string; + name: string; + redirectUri?: string; + token: string; +} + +export interface OauthLoginUser { + redirectUri: string; + token: string; +} + +export interface OauthResponse { + use: KakaoSignupUser; + refreshToken: string; + accessToken: string; +} diff --git a/src/types/oauth/oauthReq.ts b/src/types/oauth/oauthReq.ts deleted file mode 100644 index 10df9aa6..00000000 --- a/src/types/oauth/oauthReq.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface OauthUser { - location?: string; - phoneNumber?: string; - storePhoneNumber?: string; - storeName?: string; - role: string; - nickname?: string; - name: string; - redirectUri?: string; - token: string; -} From 3662cb8d1ac010472f62b7ff42e9279903a67fc8 Mon Sep 17 00:00:00 2001 From: yyezzzy Date: Fri, 6 Dec 2024 17:11:02 +0900 Subject: [PATCH 2/4] =?UTF-8?q?bugfix:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/oauth/callback/kakao/route.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/app/api/oauth/callback/kakao/route.ts b/src/app/api/oauth/callback/kakao/route.ts index fdcc8f3e..d9b07242 100644 --- a/src/app/api/oauth/callback/kakao/route.ts +++ b/src/app/api/oauth/callback/kakao/route.ts @@ -2,8 +2,8 @@ import { NextRequest, NextResponse } from "next/server"; import { OauthLoginUser, OauthResponse, OauthSignupUser } from "@/types/oauth/oauth"; import axios from "axios"; -export const GET = async (req: NextRequest) => { - const searchParams = req.nextUrl.searchParams; +export const GET = async (request: NextRequest) => { + const searchParams = request.nextUrl.searchParams; const code = searchParams.get("code"); const state = searchParams.get("state"); @@ -42,7 +42,10 @@ export const GET = async (req: NextRequest) => { }; console.log("회원가입 시도:", signupUser); - const signupResponse = await axios.post(`/api/oauth/signup`, { provider, ...signupUser }); + const signupResponse = await axios.post(`${process.env.NEXT_PUBLIC_DOMAIN_URL}/api/oauth/signup`, { + provider, + ...signupUser, + }); console.log("회원가입 성공:", signupResponse.data); } else if (action === "login") { // 로그인 로직 @@ -52,7 +55,12 @@ export const GET = async (req: NextRequest) => { }; console.log("로그인 시도", loginUser); - const loginResponse = await axios.post(`/api/oauth/login/${provider}`, { provider, ...loginUser }); + const loginResponse = await axios.post( + `${process.env.NEXT_PUBLIC_DOMAIN_URL}/api/oauth/login/${provider}`, + { + ...loginUser, + } + ); console.log("로그인 성공:", loginResponse.data); } else { return NextResponse.json({ message: "Invalid action" }, { status: 400 }); @@ -61,4 +69,6 @@ export const GET = async (req: NextRequest) => { console.error(`${provider} ${action} 에러:`, error); return NextResponse.json({ message: error.response?.data || "Internal Server Error" }, { status: 500 }); } + // 로그인 성공 후 리다이렉트 + return NextResponse.redirect(new URL("/", request.url)); }; From 7e3fe0466c9ce2194750958f948a01ceb6565748 Mon Sep 17 00:00:00 2001 From: yyezzzy Date: Sat, 7 Dec 2024 00:25:17 +0900 Subject: [PATCH 3/4] =?UTF-8?q?bugfix:=20Prettier=20format=20on=20save=20?= =?UTF-8?q?=EB=8A=90=EB=A0=A4=EC=A7=90=20=EC=84=A4=EC=A0=95=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 69d63471..89c2d401 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,5 +24,5 @@ "typeRoots": ["./node_modules/@types"] }, "include": ["next-env.d.ts", "src/**/*.ts", "src/**/*.tsx", ".next/types/**/*.ts", "custom.d.ts"], - "exclude": ["node_modules"] + "exclude": ["node_modules", ".next", ".storybook", "storybook-static"] } From 320db9d9c650c80933e7a173831936ea7fffe517 Mon Sep 17 00:00:00 2001 From: yyezzzy Date: Sat, 7 Dec 2024 00:26:41 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20OAuth=20=EA=B0=84=ED=8E=B8=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8/=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EA=B5=AC=ED=98=84=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/oauth/callback/google/route.ts | 119 ++++++++++++-------- src/app/api/oauth/callback/kakao/route.ts | 110 +++++++++++------- src/app/api/oauth/login/[provider]/route.ts | 20 +--- 3 files changed, 144 insertions(+), 105 deletions(-) diff --git a/src/app/api/oauth/callback/google/route.ts b/src/app/api/oauth/callback/google/route.ts index e51adc5e..64d21043 100644 --- a/src/app/api/oauth/callback/google/route.ts +++ b/src/app/api/oauth/callback/google/route.ts @@ -2,32 +2,26 @@ import { NextRequest, NextResponse } from "next/server"; import axios from "axios"; import { decodeJwt } from "@/middleware"; import apiClient from "@/lib/apiClient"; -import { OauthSignupUser } from "@/types/oauth/oauth"; +import { OauthLoginUser, OauthResponse, OauthSignupUser } from "@/types/oauth/oauth"; +import { cookies } from "next/headers"; -export const GET = async (req: NextRequest) => { - const searchParams = req.nextUrl.searchParams; +export const GET = async (request: NextRequest) => { + const searchParams = request.nextUrl.searchParams; const code = searchParams.get("code"); const state = searchParams.get("state"); - if (!code) { - return NextResponse.json({ message: "Code not found" }, { status: 400 }); + if (!code || !state) { + return NextResponse.json({ message: `${!code ? "Code" : "State"} not found` }, { status: 400 }); } - if (!state) { - return NextResponse.json({ message: "State not found" }, { status: 400 }); - } - - // `state`를 JSON으로 파싱 let parsedState; try { parsedState = JSON.parse(decodeURIComponent(state)); - } catch (error) { - console.error("Failed to parse state:", error); + } catch { return NextResponse.json({ message: "Invalid state format" }, { status: 400 }); } - const { provider, role } = parsedState; - + const { provider, action, role } = parsedState; const GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token"; const clientId = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID; const clientSecret = process.env.NEXT_PUBLIC_GOOGLE_SECRET; @@ -38,8 +32,8 @@ export const GET = async (req: NextRequest) => { } try { - // Access Token 요청 - const tokenResponse = await axios.post(GOOGLE_TOKEN_URL, null, { + // Google Access Token 요청 + const { data: tokenResponse } = await axios.post(GOOGLE_TOKEN_URL, null, { params: { code, client_id: clientId, @@ -49,41 +43,76 @@ export const GET = async (req: NextRequest) => { }, }); - const { id_token } = tokenResponse.data; - - // id_token 디코딩 + const { id_token } = tokenResponse; const decodedIdToken = decodeJwt(id_token); if (!decodedIdToken) { return NextResponse.json({ message: "Invalid ID token" }, { status: 400 }); } - const googleUser: OauthSignupUser = { - role: role, - name: decodedIdToken.name, - token: id_token, + const googleUser: { signup: OauthSignupUser; login: OauthLoginUser } = { + signup: { + role, + name: decodedIdToken.name, + token: id_token, + }, + login: { + token: id_token, + redirectUri, + }, }; - console.log("Google user:", googleUser); - // OAuth 회원가입 API로 회원가입 요청 - try { - const googleSignupResponse = await apiClient.post(`/oauth/sign-up/${provider}`, googleUser); - console.log("구글 회원가입 성공:", googleSignupResponse.data); - } catch (error) { - const errorMessage = (error as any).response?.data; - console.error("구글 회원가입 에러:", errorMessage); - } - // 사용자 정보를 클라이언트에 반환 - const response = NextResponse.redirect("http://localhost:3000"); - response.cookies.set("user", JSON.stringify(googleUser), { - httpOnly: true, - secure: process.env.NODE_ENV === "production", - sameSite: "strict", - maxAge: 60 * 60 * 24, // 1일 - path: "/", - }); - return response; - } catch (error) { - console.error("Google login error:", error); - return NextResponse.json({ message: "서버에러" }, { status: 500 }); + const processUser = async () => { + if (action === "signup") { + try { + const response = await apiClient.post(`/oauth/sign-up/${provider}`, googleUser.signup); + console.log("구글 회원가입 성공:", response.data); + } catch (error: any) { + if (error.response?.status === 400) { + console.log("이미 등록된 사용자입니다. 로그인 시도 중..."); + await loginUser(); + } else { + throw new Error("회원가입 중 서버 오류"); + } + } + } else if (action === "login") { + await loginUser(); + } else { + throw new Error("잘못된 작업 에러"); + } + }; + + const loginUser = async () => { + const { data: loginResponse } = await axios.post( + `${process.env.NEXT_PUBLIC_DOMAIN_URL}/api/oauth/login/${provider}`, + googleUser.login + ); + console.log("구글 로그인 성공:", loginResponse); + + // 쿠키 저장 + const { accessToken, refreshToken } = loginResponse; + setCookies(accessToken, refreshToken); + }; + + const setCookies = (accessToken: string, refreshToken: string) => { + cookies().set("accessToken", accessToken, { + httpOnly: true, + secure: process.env.NODE_ENV === "production", + sameSite: "lax", + path: "/", + }); + cookies().set("refreshToken", refreshToken, { + httpOnly: true, + secure: process.env.NODE_ENV === "production", + sameSite: "lax", + path: "/", + }); + }; + + await processUser(); + } catch (error: any) { + console.error("OAuth 처리 중 오류:", error.message || error); + return NextResponse.json({ message: error.message || "서버 오류" }, { status: 500 }); } + + return NextResponse.redirect(new URL("/", request.url)); }; diff --git a/src/app/api/oauth/callback/kakao/route.ts b/src/app/api/oauth/callback/kakao/route.ts index d9b07242..bc7a322a 100644 --- a/src/app/api/oauth/callback/kakao/route.ts +++ b/src/app/api/oauth/callback/kakao/route.ts @@ -1,28 +1,24 @@ import { NextRequest, NextResponse } from "next/server"; -import { OauthLoginUser, OauthResponse, OauthSignupUser } from "@/types/oauth/oauth"; import axios from "axios"; +import apiClient from "@/lib/apiClient"; +import { OauthLoginUser, OauthResponse, OauthSignupUser } from "@/types/oauth/oauth"; +import { cookies } from "next/headers"; export const GET = async (request: NextRequest) => { const searchParams = request.nextUrl.searchParams; const code = searchParams.get("code"); const state = searchParams.get("state"); - if (!code) { - return NextResponse.json({ message: "Code not found" }, { status: 400 }); - } - - if (!state) { - return NextResponse.json({ message: "State not found" }, { status: 400 }); + if (!code || !state) { + return NextResponse.json({ message: `${!code ? "Code" : "State"} not found` }, { status: 400 }); } let parsedState; try { parsedState = JSON.parse(decodeURIComponent(state)); - } catch (error) { - console.error("Failed to parse state:", error); + } catch { return NextResponse.json({ message: "Invalid state format" }, { status: 400 }); } - console.log("parsedState:", parsedState); const { provider, action, role } = parsedState; const redirectUri = process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URI; @@ -31,44 +27,76 @@ export const GET = async (request: NextRequest) => { return NextResponse.json({ message: "Environment variables not set" }, { status: 500 }); } - try { - if (action === "signup") { - // 회원가입 로직 - const signupUser: OauthSignupUser = { - role: role || "user", // role 값이 없으면 기본값으로 "user" 설정 - name: "", // 회원가입 시 이름은 추후 API로 받아오거나 기본값으로 처리 - token: code, // 인가코드 전달 - redirectUri, - }; - console.log("회원가입 시도:", signupUser); + const kakaoUser: { signup: OauthSignupUser; login: OauthLoginUser } = { + signup: { + role: role || "user", // 기본 역할 설정 + name: "", // Kakao는 이름을 제공하지 않으므로 기본값 + token: code, // 인가 코드 전달 + }, + login: { + token: code, // 인가 코드 전달 + redirectUri, // 리다이렉트 URI 포함 + }, + }; - const signupResponse = await axios.post(`${process.env.NEXT_PUBLIC_DOMAIN_URL}/api/oauth/signup`, { - provider, - ...signupUser, - }); - console.log("회원가입 성공:", signupResponse.data); + const processUser = async () => { + if (action === "signup") { + try { + const response = await apiClient.post(`/oauth/sign-up/${provider}`, kakaoUser.signup); + console.log("카카오 회원가입 성공:", response.data); + } catch (error: any) { + if (error.response?.status === 400) { + console.log("이미 등록된 사용자입니다. 로그인 시도 중..."); + await loginUser(); + } else { + throw new Error("회원가입 중 서버 오류"); + } + } } else if (action === "login") { - // 로그인 로직 - const loginUser: OauthLoginUser = { - token: code, - redirectUri, - }; - console.log("로그인 시도", loginUser); + await loginUser(); + } else { + throw new Error("Invalid action"); + } + }; - const loginResponse = await axios.post( + const loginUser = async () => { + try { + const { data: loginResponse } = await axios.post( `${process.env.NEXT_PUBLIC_DOMAIN_URL}/api/oauth/login/${provider}`, - { - ...loginUser, - } + kakaoUser.login ); - console.log("로그인 성공:", loginResponse.data); - } else { - return NextResponse.json({ message: "Invalid action" }, { status: 400 }); + console.log("카카오 로그인 성공:", loginResponse); + + // 쿠키 저장 + const { accessToken, refreshToken } = loginResponse; + setCookies(accessToken, refreshToken); + } catch (error: any) { + console.error("카카오 로그인 중 오류:", error.message || error); + throw new Error("로그인 중 서버 오류"); } + }; + + const setCookies = (accessToken: string, refreshToken: string) => { + cookies().set("accessToken", accessToken, { + httpOnly: true, + secure: process.env.NODE_ENV === "production", + sameSite: "lax", + path: "/", + }); + cookies().set("refreshToken", refreshToken, { + httpOnly: true, + secure: process.env.NODE_ENV === "production", + sameSite: "lax", + path: "/", + }); + }; + + try { + await processUser(); } catch (error: any) { - console.error(`${provider} ${action} 에러:`, error); - return NextResponse.json({ message: error.response?.data || "Internal Server Error" }, { status: 500 }); + console.error("OAuth 처리 중 오류:", error.message || error); + return NextResponse.json({ message: error.message || "서버 오류" }, { status: 500 }); } - // 로그인 성공 후 리다이렉트 + return NextResponse.redirect(new URL("/", request.url)); }; diff --git a/src/app/api/oauth/login/[provider]/route.ts b/src/app/api/oauth/login/[provider]/route.ts index 23be7ad0..08bfc0db 100644 --- a/src/app/api/oauth/login/[provider]/route.ts +++ b/src/app/api/oauth/login/[provider]/route.ts @@ -20,24 +20,6 @@ export async function POST(request: Request, { params }: { params: { provider: s // OAuth 로그인 요청 const response = await apiClient.post(`/oauth/sign-in/${provider}`, body); - // 응답에서 토큰 추출 - const { accessToken, refreshToken } = response.data; - - // 쿠키에 토큰 저장 - cookies().set("accessToken", accessToken, { - httpOnly: true, - secure: process.env.NODE_ENV === "production", - sameSite: "lax", - path: "/", - }); - - cookies().set("refreshToken", refreshToken, { - httpOnly: true, - secure: process.env.NODE_ENV === "production", - sameSite: "lax", - path: "/", - }); - return NextResponse.json(response.data); } catch (error: unknown) { if (error instanceof AxiosError) { @@ -46,6 +28,6 @@ export async function POST(request: Request, { params }: { params: { provider: s return NextResponse.json({ message: error.response.data.message }, { status: error.response.status }); } } - return NextResponse.json({ message: "Internal Server Error" }, { status: 500 }); + return NextResponse.json({ message: "서버오류" }, { status: 500 }); } }