summaryrefslogtreecommitdiff
path: root/lib/users/session
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-10-13 18:24:00 +0900
committerjoonhoekim <26rote@gmail.com>2025-10-13 18:24:00 +0900
commit80e3d0befed487e0447bacffd76ed6539f01e992 (patch)
treede5762bea7161e3dd949401b2d985b6723fd32ee /lib/users/session
parentff8a168f9fc67b345f4d32065e55f0901ba05b4c (diff)
(김준회) S-GIPS 로그인시 유저 선택해 sms 전송 처리
Diffstat (limited to 'lib/users/session')
-rw-r--r--lib/users/session/helper.ts65
1 files changed, 58 insertions, 7 deletions
diff --git a/lib/users/session/helper.ts b/lib/users/session/helper.ts
index f99ca80a..03bfd7bc 100644
--- a/lib/users/session/helper.ts
+++ b/lib/users/session/helper.ts
@@ -6,20 +6,35 @@ export const authHelpers = {
// 1차 인증 검증 및 임시 키 생성 (DB 버전)
async performFirstAuth(username: string, password: string, provider: 'email' | 'sgips') {
console.log('performFirstAuth started:', { username, provider })
-
+
try {
let authResult;
-
+
if (provider === 'sgips') {
authResult = await authenticateWithSGips(username, password)
} else {
authResult = await verifyExternalCredentials(username, password)
}
-
- if (!authResult.success || !authResult.user) {
+
+ if (!authResult.success) {
return { success: false, error: authResult.error || 'INVALID_CREDENTIALS' }
}
-
+
+ // S-GIPS의 경우 otpUsers 배열 반환
+ if (provider === 'sgips' && authResult.otpUsers) {
+ console.log('S-GIPS auth successful with otpUsers:', authResult.otpUsers.length)
+
+ return {
+ success: true,
+ otpUsers: authResult.otpUsers
+ }
+ }
+
+ // 일반 사용자의 경우 기존 로직
+ if (!authResult.user) {
+ return { success: false, error: 'INVALID_CREDENTIALS' }
+ }
+
// DB에 임시 인증 세션 생성
const expiresAt = new Date(Date.now() + (10 * 60 * 1000)) // 10분 후 만료
const tempAuthKey = await SessionRepository.createTempAuthSession({
@@ -28,7 +43,7 @@ export const authHelpers = {
authMethod: provider,
expiresAt
})
-
+
console.log('Temp auth stored in DB:', {
tempAuthKey,
userId: authResult.user.id,
@@ -36,7 +51,7 @@ export const authHelpers = {
authMethod: provider,
expiresAt
})
-
+
return {
success: true,
tempAuthKey,
@@ -57,6 +72,42 @@ export const authHelpers = {
// 임시 인증 정보 삭제 (DB 버전)
async clearTempAuth(tempAuthKey: string) {
await SessionRepository.markTempAuthSessionAsUsed(tempAuthKey)
+ },
+
+ // 선택된 S-GIPS 사용자에 대한 임시 인증 세션 생성
+ async createTempAuthForSelectedUser(selectedUser: {
+ userId: number;
+ email: string;
+ name: string;
+ }) {
+ console.log('Creating temp auth for selected S-GIPS user:', selectedUser)
+
+ try {
+ const expiresAt = new Date(Date.now() + (10 * 60 * 1000)) // 10분 후 만료
+ const tempAuthKey = await SessionRepository.createTempAuthSession({
+ userId: selectedUser.userId,
+ email: selectedUser.email,
+ authMethod: 'sgips',
+ expiresAt
+ })
+
+ console.log('Temp auth created for selected user:', {
+ tempAuthKey,
+ userId: selectedUser.userId,
+ email: selectedUser.email,
+ expiresAt
+ })
+
+ return {
+ success: true,
+ tempAuthKey,
+ userId: selectedUser.userId,
+ email: selectedUser.email
+ }
+ } catch (error) {
+ console.error('Error creating temp auth for selected user:', error)
+ return { success: false, error: 'SYSTEM_ERROR' }
+ }
}
}
\ No newline at end of file