@thinkingcat/auth-utils 1.0.22 → 1.0.23

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 +27 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -419,14 +419,21 @@ async function createAuthResponse(accessToken, secret, options) {
419
419
  const { payload } = tokenResult;
420
420
  // 2. NextAuth JWT 생성
421
421
  const jwt = createNextAuthJWT(payload, serviceId);
422
+ // refreshToken 추가
423
+ if (refreshToken) {
424
+ jwt.refreshToken = refreshToken;
425
+ }
426
+ // accessTokenExpires 추가 (15분)
427
+ jwt.accessTokenExpires = Date.now() + (15 * 60 * 1000);
422
428
  debugLog('createAuthResponse', 'JWT created:', {
423
429
  hasId: !!jwt.id,
424
430
  hasEmail: !!jwt.email,
425
431
  hasRole: !!jwt.role,
432
+ hasRefreshToken: !!jwt.refreshToken,
426
433
  });
427
- // 3. NextAuth 세션 토큰 생성 전략
428
- // NextAuth의 JWT 콜백이 custom tokens를 읽어서 자동으로 NextAuth 세션을 생성
429
- debugLog('createAuthResponse', 'Custom tokens will be set, NextAuth JWT callback will handle session creation');
434
+ // 3. NextAuth session cookie 생성
435
+ const nextAuthToken = await encodeNextAuthToken(jwt, secret);
436
+ debugLog('createAuthResponse', 'NextAuth session token encoded');
430
437
  // 5. HTML 생성
431
438
  const displayText = text || serviceId;
432
439
  const html = redirectPath
@@ -440,7 +447,23 @@ async function createAuthResponse(accessToken, secret, options) {
440
447
  'Content-Type': 'text/html',
441
448
  },
442
449
  });
443
- // 4. 쿠키 설정
450
+ // 4. NextAuth session cookie 설정
451
+ const nextAuthCookieName = isProduction
452
+ ? '__Secure-next-auth.session-token'
453
+ : 'next-auth.session-token';
454
+ const cookieOptions = {
455
+ httpOnly: true,
456
+ secure: isProduction,
457
+ sameSite: isProduction ? 'none' : 'lax',
458
+ path: '/',
459
+ maxAge: 30 * 24 * 60 * 60, // 30일
460
+ };
461
+ if (cookieDomain) {
462
+ cookieOptions.domain = cookieDomain;
463
+ }
464
+ response.cookies.set(nextAuthCookieName, nextAuthToken, cookieOptions);
465
+ debugLog('createAuthResponse', 'NextAuth session cookie set:', nextAuthCookieName);
466
+ // 5. 커스텀 토큰 쿠키 설정
444
467
  if (refreshToken) {
445
468
  setCustomTokens(response, accessToken, refreshToken, {
446
469
  cookiePrefix,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkingcat/auth-utils",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
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",