summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/users/auth/verifyCredentails.ts26
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 {