summaryrefslogtreecommitdiff
path: root/lib/users/session/helper.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-07-07 01:44:45 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-07-07 01:44:45 +0000
commit90f79a7a691943a496f67f01c1e493256070e4de (patch)
tree37275fde3ae08c2bca384fbbc8eb378de7e39230 /lib/users/session/helper.ts
parentfbb3b7f05737f9571b04b0a8f4f15c0928de8545 (diff)
(대표님) 변경사항 20250707 10시 43분 - unstaged 변경사항 추가
Diffstat (limited to 'lib/users/session/helper.ts')
-rw-r--r--lib/users/session/helper.ts62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/users/session/helper.ts b/lib/users/session/helper.ts
new file mode 100644
index 00000000..439ab32d
--- /dev/null
+++ b/lib/users/session/helper.ts
@@ -0,0 +1,62 @@
+import { authenticateWithSGips, verifyExternalCredentials } from "../auth/verifyCredentails";
+import { SessionRepository } from "./repository";
+
+// lib/session/helpers.ts - NextAuth 헬퍼 함수들 개선
+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) {
+ return { success: false, error: 'Invalid credentials' }
+ }
+
+ // DB에 임시 인증 세션 생성
+ const expiresAt = new Date(Date.now() + (10 * 60 * 1000)) // 10분 후 만료
+ const tempAuthKey = await SessionRepository.createTempAuthSession({
+ userId: authResult.user.id,
+ email: authResult.user.email,
+ authMethod: provider,
+ expiresAt
+ })
+
+ console.log('Temp auth stored in DB:', {
+ tempAuthKey,
+ userId: authResult.user.id,
+ email: authResult.user.email,
+ authMethod: provider,
+ expiresAt
+ })
+
+ return {
+ success: true,
+ tempAuthKey,
+ userId: authResult.user.id,
+ email: authResult.user.email
+ }
+ } catch (error) {
+ console.error('First auth error:', error)
+ return { success: false, error: 'Authentication failed' }
+ }
+ },
+
+ // 임시 인증 정보 조회 (DB 버전)
+ async getTempAuth(tempAuthKey: string) {
+ return await SessionRepository.getTempAuthSession(tempAuthKey)
+ },
+
+ // 임시 인증 정보 삭제 (DB 버전)
+ async clearTempAuth(tempAuthKey: string) {
+ await SessionRepository.markTempAuthSessionAsUsed(tempAuthKey)
+ }
+ }
+ \ No newline at end of file