diff options
| author | joonhoekim <26rote@gmail.com> | 2025-10-14 18:12:55 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-10-14 18:12:55 +0900 |
| commit | 1b038cb6413a6a579c58beb71eca83fa6657c1d4 (patch) | |
| tree | bb59e1591723c6cf6da54a1dd11fdc19f5a328f3 /lib/users | |
| parent | 5fe800c27ff8caabbb0ac64c5dab8062aac43684 (diff) | |
(김준회) SGIPS 전화번호 정규화 및 로깅 코드 제거
Diffstat (limited to 'lib/users')
| -rw-r--r-- | lib/users/auth/verifyCredentails.ts | 26 |
1 files changed, 20 insertions, 6 deletions
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 { |
