From 9032729005fa639d2eef97dbea075e5b7864414c Mon Sep 17 00:00:00 2001 From: dasosann Date: Fri, 20 Feb 2026 17:30:47 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20api?= =?UTF-8?q?=20=EC=97=B0=EA=B2=B0=20serverAction=EC=9C=BC=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/actions/loginAction.ts | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/actions/loginAction.ts b/lib/actions/loginAction.ts index 5260d69..9e38c40 100644 --- a/lib/actions/loginAction.ts +++ b/lib/actions/loginAction.ts @@ -1,10 +1,18 @@ "use server"; +import { serverApi } from "@/lib/server-api"; + type LoginState = { success: boolean; message: string; }; +type LoginResponse = { + code: string; + status: number; + message: string; +}; + export async function loginAction( prevState: LoginState, formData: FormData, @@ -12,20 +20,14 @@ export async function loginAction( const email = formData.get("email"); const password = formData.get("password"); - // Mock delay - await new Promise((resolve) => setTimeout(resolve, 1000)); - - // TODO: 실제 백엔드 API 호출로 교체 필요 - // const response = await fetch("https://api.comatching.com/login", { - // method: "POST", - // body: JSON.stringify({ email, password }), - // headers: { "Content-Type": "application/json" }, - // }); - - // Mock logic - if (email === "test@test.com" && password === "1234") { - return { success: true, message: "" }; + try { + await serverApi.post({ + path: "/api/auth/login", + body: { email, password }, + }); + } catch { + return { success: false, message: "이메일 혹은 비밀번호가 틀립니다" }; } - return { success: false, message: "이메일 혹은 비밀번호가 틀립니다" }; + return { success: true, message: "로그인 성공" }; } From af4296f6e5b6af9f8a58884e48b64464aabcc744 Mon Sep 17 00:00:00 2001 From: dasosann Date: Fri, 20 Feb 2026 17:47:08 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=B2=98=EB=A6=AC=20=EA=B0=9C=EC=84=A0=20?= =?UTF-8?q?=EB=B0=8F=20=EC=98=88=EC=99=B8=20=EB=A1=9C=EA=B9=85=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/actions/loginAction.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/actions/loginAction.ts b/lib/actions/loginAction.ts index 9e38c40..7f21f9b 100644 --- a/lib/actions/loginAction.ts +++ b/lib/actions/loginAction.ts @@ -1,6 +1,7 @@ "use server"; import { serverApi } from "@/lib/server-api"; +import { isAxiosError } from "axios"; type LoginState = { success: boolean; @@ -25,8 +26,23 @@ export async function loginAction( path: "/api/auth/login", body: { email, password }, }); - } catch { - return { success: false, message: "이메일 혹은 비밀번호가 틀립니다" }; + } catch (error) { + if (isAxiosError(error)) { + const status = error.response?.status; + if (status === 400 || status === 401) { + return { success: false, message: "이메일 혹은 비밀번호가 틀립니다" }; + } + console.error("[loginAction] API error", { + status, + data: error.response?.data, + }); + } else { + console.error("[loginAction] Unexpected error", error); + } + return { + success: false, + message: "서버 오류가 발생했습니다. 잠시 후 다시 시도해주세요.", + }; } return { success: true, message: "로그인 성공" };