diff options
| author | joonhoekim <26rote@gmail.com> | 2025-11-05 10:43:11 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-11-05 10:43:11 +0900 |
| commit | a6ad5fcfb65772b9ae240d9fa02bf9ed1a9160c9 (patch) | |
| tree | b2ce111bb2865fcf44c59adf0ac8968d02c37e56 | |
| parent | 47fb72704161b4b58a27c7f5c679fc44618de9a1 (diff) | |
(김준회) 세션에 epId 추가
| -rw-r--r-- | app/api/auth/[...nextauth]/route.ts | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index be50c022..75ddfe85 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -37,6 +37,7 @@ declare module "next-auth" { sessionExpiredAt?: number | null dbSessionId?: string | null roles?: string[] // ✅ roles 배열 추가 + epId?: string | null // ✅ epId 추가 (users 테이블에서) } } @@ -51,6 +52,7 @@ declare module "next-auth" { authMethod?: AuthMethod dbSessionId?: string | null roles?: string[] // ✅ roles 배열 추가 + epId?: string | null // ✅ epId 추가 (users 테이블에서) } } @@ -67,6 +69,7 @@ declare module "next-auth/jwt" { sessionExpiredAt?: number | null dbSessionId?: string | null roles?: string[] // ✅ roles 배열 추가 + epId?: string | null // ✅ epId 추가 (users 테이블에서) } } @@ -161,6 +164,7 @@ export const authOptions: NextAuthOptions = { reAuthTime, authMethod: 'otp' as AuthMethod, roles: userRoles, // ✅ roles 배열 추가 + epId: user.epId, // ✅ epId 추가 (users 테이블에서) } }, }), @@ -320,6 +324,7 @@ export const authOptions: NextAuthOptions = { token.dbSessionId = user.dbSessionId token.roles = user.roles token.ownerCompanyId = user.ownerCompanyId + token.epId = user.epId // ✅ epId 추가 } // ✅ 기존 토큰이 있고 로그인이 아닌 경우, DB에서 최신 사용자 정보 조회 @@ -339,6 +344,7 @@ export const authOptions: NextAuthOptions = { token.companyId = latestUser.companyId token.techCompanyId = latestUser.techCompanyId token.ownerCompanyId = latestUser.ownerCompanyId + token.epId = latestUser.epId // ✅ epId 최신 정보로 업데이트 // roles 정보도 최신으로 업데이트 const userRoles = await getUserRoles(parseInt(token.id)) @@ -365,6 +371,7 @@ export const authOptions: NextAuthOptions = { token.companyId = latestUser.companyId token.techCompanyId = latestUser.techCompanyId token.ownerCompanyId = latestUser.ownerCompanyId + token.epId = latestUser.epId // ✅ SAML 시 epId 설정 token.roles = await getUserRoles(numericUserId) } @@ -444,6 +451,7 @@ export const authOptions: NextAuthOptions = { sessionExpiredAt: token.sessionExpiredAt as number | null, dbSessionId: token.dbSessionId as string | null, roles: token.roles as string[] || [], // ✅ roles 정보 추가 + epId: token.epId as string | null, // ✅ epId 추가 } } return session |
