@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.
Files changed (2) hide show
  1. package/dist/index.js +24 -7
  2. 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: (payload.name || payload.email || 'User'), // name이 없으면 email 또는 기본값 사용
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
- // 주의: NextAuth 세션 쿠키를 자동으로 관리하므로, 직접 설정하는 것이 문제를 일으킬 수 있습니다.
661
- // 따라서 커스텀 토큰만 설정하고, NextAuth 세션은 JWT 콜백에서 처리하도록 합니다.
662
- debugLog('verifyAndRefreshToken', 'Skipping NextAuth session cookie - will be handled by NextAuth JWT callback', {
663
- hasJWT: !!jwt,
664
- jwtId: jwt?.id,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkingcat/auth-utils",
3
- "version": "1.0.45",
3
+ "version": "1.0.47",
4
4
  "description": "Authentication utilities for ThinkingCat SSO services with conditional logging",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",