@thinkingcat/auth-utils 1.0.45 → 1.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +24 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -164,10 +164,16 @@ function createNextAuthJWT(payload, serviceId) {
|
|
|
164
164
|
const services = payload.services || [];
|
|
165
165
|
const service = services.find((s) => s.serviceId === serviceId);
|
|
166
166
|
const effectiveRole = service?.role || payload.role || 'ADMIN';
|
|
167
|
+
// name 필드 결정: payload.name이 있으면 사용, 없으면 decryptedEmail 또는 maskedEmail 사용
|
|
168
|
+
// email은 암호화되어 있을 수 있으므로 직접 사용하지 않음
|
|
169
|
+
const displayName = payload.name
|
|
170
|
+
|| payload.decryptedEmail
|
|
171
|
+
|| payload.maskedEmail
|
|
172
|
+
|| 'User';
|
|
167
173
|
const jwt = {
|
|
168
174
|
id: (payload.id || payload.sub),
|
|
169
175
|
email: payload.email,
|
|
170
|
-
name:
|
|
176
|
+
name: displayName,
|
|
171
177
|
role: effectiveRole, // Role enum 타입 (string으로 캐스팅)
|
|
172
178
|
services: payload.services,
|
|
173
179
|
phoneVerified: payload.phoneVerified ?? false,
|
|
@@ -657,12 +663,23 @@ async function verifyAndRefreshToken(req, secret, options) {
|
|
|
657
663
|
}
|
|
658
664
|
jwt.accessTokenExpires = Date.now() + (15 * 60 * 1000);
|
|
659
665
|
// NextAuth 세션 쿠키 생성
|
|
660
|
-
//
|
|
661
|
-
//
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
+
// 미들웨어에서는 NextAuth JWT callback이 실행되지 않으므로,
|
|
667
|
+
// refresh 후 NextAuth 세션 쿠키를 직접 설정해야 합니다.
|
|
668
|
+
try {
|
|
669
|
+
const encodedSessionToken = await encodeNextAuthToken(jwt, secret, 30 * 24 * 60 * 60);
|
|
670
|
+
setNextAuthToken(response, encodedSessionToken, {
|
|
671
|
+
isProduction,
|
|
672
|
+
cookieDomain,
|
|
673
|
+
});
|
|
674
|
+
debugLog('verifyAndRefreshToken', 'NextAuth session cookie set successfully', {
|
|
675
|
+
hasJWT: !!jwt,
|
|
676
|
+
jwtId: jwt?.id,
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
catch (error) {
|
|
680
|
+
debugError('verifyAndRefreshToken', 'Failed to set NextAuth session cookie:', error);
|
|
681
|
+
// NextAuth 세션 쿠키 설정 실패해도 커스텀 토큰은 설정하므로 계속 진행
|
|
682
|
+
}
|
|
666
683
|
// 커스텀 토큰 쿠키 설정
|
|
667
684
|
if (newRefreshToken) {
|
|
668
685
|
setCustomTokens(response, refreshResult.accessToken, newRefreshToken, {
|
package/package.json
CHANGED