summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-10-14 17:24:40 +0900
committerjoonhoekim <26rote@gmail.com>2025-10-14 17:24:40 +0900
commit6892880c16af3eb0027a77c9695b2fe462b4761e (patch)
treea650a131cf46af00048b10db873eea70dc7196cd
parentb61931f50ba63f9a91ac8eb01fd91aa6e2fb6119 (diff)
(김준회) S-GIPS 유저 로그인 SMS 송신 오류 개선 및 로깅 추가
-rw-r--r--app/api/auth/send-sms/route.ts17
-rw-r--r--components/login/login-form.tsx37
-rw-r--r--lib/users/auth/verifyCredentails.ts3
3 files changed, 44 insertions, 13 deletions
diff --git a/app/api/auth/send-sms/route.ts b/app/api/auth/send-sms/route.ts
index 805ff7f7..707741dc 100644
--- a/app/api/auth/send-sms/route.ts
+++ b/app/api/auth/send-sms/route.ts
@@ -4,6 +4,7 @@ import { NextRequest, NextResponse } from 'next/server';
import { z } from 'zod';
import { getUserById } from '@/lib/users/repository';
import { generateAndSendSmsToken } from '@/lib/users/auth/passwordUtil';
+import { debugLog, debugSuccess, debugError } from '@/lib/debug-utils';
const sendSmsSchema = z.object({
userId: z.number(),
@@ -15,7 +16,11 @@ export async function POST(request: NextRequest) {
const body = await request.json();
const { userId } = sendSmsSchema.parse(body);
- console.log(userId, "userId")
+ debugLog('SMS 전송 요청', {
+ userId,
+ receivedPhone: body.phone,
+ receivedName: body.name
+ });
// 본인 확인
if (!userId) {
@@ -28,15 +33,19 @@ export async function POST(request: NextRequest) {
// 사용자 정보 조회
const user = await getUserById(userId);
if (!user || !user.phone) {
+ debugError('사용자 정보 조회 실패', { userId, userFound: !!user, phoneExists: !!user?.phone });
return NextResponse.json(
{ error: '전화번호가 등록되지 않았습니다' },
{ status: 400 }
);
}
- console.log(user, "user")
-
-
+ debugSuccess('DB에서 조회된 사용자 정보', {
+ userId: user.id,
+ email: user.email,
+ phone: user.phone,
+ name: user.name
+ });
// SMS 전송
const result = await generateAndSendSmsToken(Number(userId), user.phone);
diff --git a/components/login/login-form.tsx b/components/login/login-form.tsx
index b0a0e574..2fdf7cce 100644
--- a/components/login/login-form.tsx
+++ b/components/login/login-form.tsx
@@ -21,6 +21,7 @@ import {
} from "@/components/ui/input-otp"
import { requestPasswordResetAction } from "@/lib/users/auth/partners-auth";
import Loading from "../common/loading/loading";
+import { debugLog, debugSuccess, debugProcess } from "@/lib/debug-utils";
type LoginMethod = 'username' | 'sgips';
@@ -208,14 +209,29 @@ export function LoginForm() {
const targetUserId = userIdParam || mfaUserId;
if (!targetUserId || mfaCountdown > 0) return;
+ debugLog('SMS 전송 시작', {
+ userIdParam,
+ mfaUserId,
+ targetUserId,
+ selectedOtpUser: selectedOtpUser ? {
+ userId: selectedOtpUser.userId,
+ email: selectedOtpUser.email,
+ phone: selectedOtpUser.phone,
+ name: selectedOtpUser.name
+ } : null
+ });
+
setIsSmsLoading(true);
try {
- const requestBody: any = { userId: targetUserId };
+ const requestBody: { userId: number; phone?: string; name?: string } = { userId: targetUserId };
// S-GIPS 사용자인 경우 추가 정보 포함
if (selectedOtpUser) {
requestBody.phone = selectedOtpUser.phone;
requestBody.name = selectedOtpUser.name;
+ debugSuccess('S-GIPS 사용자 정보 포함', { phone: selectedOtpUser.phone, name: selectedOtpUser.name });
+ } else {
+ debugLog('일반 사용자 (selectedOtpUser 없음)');
}
const response = await fetch('/api/auth/send-sms', {
@@ -453,6 +469,14 @@ export function LoginForm() {
// 선택된 OTP 사용자와 함께 MFA 진행
const proceedWithSelectedUser = async (user: OtpUser, tempAuthKey: string) => {
try {
+ debugProcess('선택된 S-GIPS 사용자로 MFA 진행', {
+ userId: user.userId,
+ email: user.email,
+ phone: user.phone,
+ name: user.name,
+ tempAuthKey
+ });
+
// 사용자 정보를 기반으로 MFA 진행
setTempAuthKey(tempAuthKey);
setSelectedOtpUser(user);
@@ -460,14 +484,11 @@ export function LoginForm() {
setMfaUserEmail(user.email);
setShowMfaForm(true);
- // 선택된 사용자의 정보를 이용해 SMS 전송 준비
- // 실제로는 userId가 필요하므로 API에서 받아와야 함
- // 여기서는 임시로 user 객체를 저장하고 SMS 전송 시 사용
+ // 선택된 사용자의 userId를 직접 전달하여 SMS 전송
setTimeout(() => {
- // 실제 구현에서는 user 정보를 기반으로 SMS 전송
- // 현재는 기존 로직 유지하되, 선택된 사용자 정보 활용
- handleSendSms();
- }, 500);
+ debugLog('SMS 전송 타이머 실행 (2000ms 후)', { userId: user.userId });
+ handleSendSms(user.userId);
+ }, 2000);
toast({
title: t('sgipsAuthComplete'),
diff --git a/lib/users/auth/verifyCredentails.ts b/lib/users/auth/verifyCredentails.ts
index ff8f9596..64bf9b28 100644
--- a/lib/users/auth/verifyCredentails.ts
+++ b/lib/users/auth/verifyCredentails.ts
@@ -19,6 +19,7 @@ import {
} from '@/db/schema';
import { headers } from 'next/headers';
import { verifySmsToken } from './passwordUtil';
+import { debugSuccess } from '@/lib/debug-utils';
// 에러 타입 정의
export type AuthError =
@@ -602,7 +603,7 @@ export async function verifySGipsCredentials(
.where(eq(users.id, localUser[0].id));
userId = localUser[0].id;
- console.log(`S-GIPS 사용자 정보 업데이트: ${otpUser.email} - phone: ${otpUser.phone}`);
+ debugSuccess('S-GIPS 사용자 정보 업데이트', { email: otpUser.email, phone: otpUser.phone });
}
return {