summaryrefslogtreecommitdiff
path: root/app/api/auth/select-sgips-user/route.ts
diff options
context:
space:
mode:
Diffstat (limited to 'app/api/auth/select-sgips-user/route.ts')
-rw-r--r--app/api/auth/select-sgips-user/route.ts85
1 files changed, 85 insertions, 0 deletions
diff --git a/app/api/auth/select-sgips-user/route.ts b/app/api/auth/select-sgips-user/route.ts
new file mode 100644
index 00000000..75c2012f
--- /dev/null
+++ b/app/api/auth/select-sgips-user/route.ts
@@ -0,0 +1,85 @@
+// /api/auth/select-sgips-user/route.ts
+// 선택된 S-GIPS 사용자에 대한 임시 인증 세션 생성 API 엔드포인트
+
+import { authHelpers } from '@/lib/users/session/helper'
+import { NextRequest, NextResponse } from 'next/server'
+
+// 요청 데이터 타입
+interface SelectUserRequest {
+ userId: number
+ email: string
+ name: string
+}
+
+// 응답 데이터 타입
+interface SelectUserResponse {
+ success: boolean
+ tempAuthKey?: string
+ userId?: number
+ email?: string
+ error?: string
+}
+
+export async function POST(request: NextRequest): Promise<NextResponse<SelectUserResponse>> {
+ try {
+ // 요청 데이터 파싱
+ const body: SelectUserRequest = await request.json()
+ const { userId, email, name } = body
+
+ // 입력 검증
+ if (!userId || !email || !name) {
+ return NextResponse.json(
+ {
+ success: false,
+ error: '필수 입력값이 누락되었습니다.'
+ },
+ { status: 400 }
+ )
+ }
+
+ // 선택된 사용자에 대한 임시 인증 세션 생성
+ const result = await authHelpers.createTempAuthForSelectedUser({
+ userId,
+ email,
+ name
+ })
+
+ if (!result.success) {
+ return NextResponse.json(
+ {
+ success: false,
+ error: '임시 인증 세션 생성에 실패했습니다.'
+ },
+ { status: 500 }
+ )
+ }
+
+ // 성공 응답
+ return NextResponse.json({
+ success: true,
+ tempAuthKey: result.tempAuthKey,
+ userId: result.userId,
+ email: result.email
+ })
+
+ } catch (error) {
+ console.error('Select S-GIPS user API error:', error)
+
+ // 에러 응답
+ return NextResponse.json(
+ {
+ success: false,
+ error: '서버 오류가 발생했습니다. 잠시 후 다시 시도해주세요.'
+ },
+ { status: 500 }
+ )
+ }
+}
+
+// GET 요청은 지원하지 않음
+export async function GET() {
+ return NextResponse.json(
+ { error: 'Method not allowed' },
+ { status: 405 }
+ )
+}