summaryrefslogtreecommitdiff
path: root/app/api/auth
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-04-08 03:08:19 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-04-08 03:08:19 +0000
commit9ceed79cf32c896f8a998399bf1b296506b2cd4a (patch)
treef84750fa6cac954d5e31221fc47a54c655fc06a9 /app/api/auth
parent230ce796836c25df26c130dbcd616ef97d12b2ec (diff)
로그인 및 미들웨어 처리. 구조 변경
Diffstat (limited to 'app/api/auth')
-rw-r--r--app/api/auth/[...nextauth]/route.ts42
1 files changed, 40 insertions, 2 deletions
diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts
index 609a63d7..cd91774c 100644
--- a/app/api/auth/[...nextauth]/route.ts
+++ b/app/api/auth/[...nextauth]/route.ts
@@ -8,7 +8,7 @@ import { JWT } from "next-auth/jwt"
import CredentialsProvider from 'next-auth/providers/credentials'
-import { verifyOtp } from '@/lib/users/verifyOtp'
+import { verifyExternalCredentials, verifyOtp } from '@/lib/users/verifyOtp'
// 1) 모듈 보강 선언
declare module "next-auth" {
@@ -61,7 +61,7 @@ export const authOptions: NextAuthOptions = {
}
return {
- id: String(user.id ?? email ?? "dts"),
+ id: String(user.id ?? email ?? "dts"),
email: user.email,
imageUrl: user.imageUrl ?? null,
name: user.name, // DB에서 가져온 실제 이름
@@ -69,6 +69,44 @@ export const authOptions: NextAuthOptions = {
domain: user.domain, // DB에서 가져온 실제 이름
}
},
+ }),
+ // 새로 추가할 ID/비밀번호 provider
+ CredentialsProvider({
+ id: 'credentials-password',
+ name: 'Username Password',
+ credentials: {
+ username: { label: "Username", type: "text" },
+ password: { label: "Password", type: "password" }
+ },
+ async authorize(credentials, req) { // req 매개변수 추가
+ if (!credentials?.username || !credentials?.password) {
+ return null;
+ }
+
+ try {
+ // 여기서 외부 서비스 API를 호출하여 사용자 인증
+ const user = await verifyExternalCredentials(
+ credentials.username,
+ credentials.password
+ );
+
+ if (user) {
+ return {
+ id: String(user.id), // id를 string으로 변환
+ name: user.name,
+ email: user.email,
+ // 첫 번째 provider와 동일한 필드 구조 유지
+ imageUrl: user.imageUrl ?? null,
+ companyId: user.companyId,
+ domain: user.domain
+ };
+ }
+ return null;
+ } catch (error) {
+ console.error("Authentication error:", error);
+ return null;
+ }
+ }
})
],
// (3) session.strategy는 'jwt'가 되도록 선언