summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-10-14 18:12:55 +0900
committerjoonhoekim <26rote@gmail.com>2025-10-14 18:12:55 +0900
commit1b038cb6413a6a579c58beb71eca83fa6657c1d4 (patch)
treebb59e1591723c6cf6da54a1dd11fdc19f5a328f3
parent5fe800c27ff8caabbb0ac64c5dab8062aac43684 (diff)
(김준회) SGIPS 전화번호 정규화 및 로깅 코드 제거
-rw-r--r--app/api/auth/send-sms/route.ts13
-rw-r--r--components/login/login-form.tsx24
-rw-r--r--lib/users/auth/verifyCredentails.ts26
3 files changed, 21 insertions, 42 deletions
diff --git a/app/api/auth/send-sms/route.ts b/app/api/auth/send-sms/route.ts
index 707741dc..53c8ab2d 100644
--- a/app/api/auth/send-sms/route.ts
+++ b/app/api/auth/send-sms/route.ts
@@ -4,7 +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';
+import { debugError } from '@/lib/debug-utils';
const sendSmsSchema = z.object({
userId: z.number(),
@@ -16,11 +16,6 @@ export async function POST(request: NextRequest) {
const body = await request.json();
const { userId } = sendSmsSchema.parse(body);
- debugLog('SMS 전송 요청', {
- userId,
- receivedPhone: body.phone,
- receivedName: body.name
- });
// 본인 확인
if (!userId) {
@@ -40,12 +35,6 @@ export async function POST(request: NextRequest) {
);
}
- 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 2fdf7cce..090f3a70 100644
--- a/components/login/login-form.tsx
+++ b/components/login/login-form.tsx
@@ -21,7 +21,6 @@ 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';
@@ -209,18 +208,6 @@ 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: { userId: number; phone?: string; name?: string } = { userId: targetUserId };
@@ -229,9 +216,6 @@ export function LoginForm() {
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', {
@@ -469,13 +453,6 @@ 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);
@@ -486,7 +463,6 @@ export function LoginForm() {
// 선택된 사용자의 userId를 직접 전달하여 SMS 전송
setTimeout(() => {
- debugLog('SMS 전송 타이머 실행 (2000ms 후)', { userId: user.userId });
handleSendSms(user.userId);
}, 2000);
diff --git a/lib/users/auth/verifyCredentails.ts b/lib/users/auth/verifyCredentails.ts
index 64bf9b28..e3c88804 100644
--- a/lib/users/auth/verifyCredentails.ts
+++ b/lib/users/auth/verifyCredentails.ts
@@ -18,8 +18,7 @@ import {
vendors
} from '@/db/schema';
import { headers } from 'next/headers';
-import { verifySmsToken } from './passwordUtil';
-import { debugSuccess } from '@/lib/debug-utils';
+import { verifySmsToken, normalizePhoneNumber } from './passwordUtil';
// 에러 타입 정의
export type AuthError =
@@ -558,6 +557,14 @@ export async function verifySGipsCredentials(
let userId: number;
if (!localUser[0]) {
+ // 전화번호 정규화 (010-1234-5678 → +821012345678)
+ const normalizedPhone = normalizePhoneNumber(otpUser.phone, 'KR');
+
+ if (!normalizedPhone) {
+ console.error(`전화번호 정규화 실패: ${otpUser.phone}`);
+ throw new Error('Invalid phone number format');
+ }
+
// 사용자가 없으면 벤더코드로 벤더 정보 조회 후 새 사용자 생성
const vendorInfo = await getVendorByCode(otpUser.vndrcd);
@@ -569,7 +576,7 @@ export async function verifySGipsCredentials(
.values({
name: otpUser.name,
email: otpUser.email,
- phone: otpUser.phone,
+ phone: normalizedPhone,
domain: 'partners',
mfaEnabled: true,
})
@@ -583,7 +590,7 @@ export async function verifySGipsCredentials(
.values({
name: otpUser.name,
email: otpUser.email,
- phone: otpUser.phone,
+ phone: normalizedPhone,
companyId: vendorInfo.id,
domain: 'partners',
mfaEnabled: true,
@@ -593,17 +600,24 @@ export async function verifySGipsCredentials(
userId = newUser[0].id;
}
} else {
+ // 전화번호 정규화 (010-1234-5678 → +821012345678)
+ const normalizedPhone = normalizePhoneNumber(otpUser.phone, 'KR');
+
+ if (!normalizedPhone) {
+ console.error(`전화번호 정규화 실패: ${otpUser.phone}`);
+ throw new Error('Invalid phone number format');
+ }
+
// 기존 사용자가 있으면 S-GIPS 정보로 전화번호 업데이트
await db
.update(users)
.set({
- phone: otpUser.phone,
+ phone: normalizedPhone,
name: otpUser.name,
})
.where(eq(users.id, localUser[0].id));
userId = localUser[0].id;
- debugSuccess('S-GIPS 사용자 정보 업데이트', { email: otpUser.email, phone: otpUser.phone });
}
return {