@thinkingcat/auth-utils 1.0.32 → 1.0.34

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 +8 -57
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -449,47 +449,19 @@ async function createAuthResponse(accessToken, secret, options) {
449
449
  }
450
450
  // accessTokenExpires 추가 (15분)
451
451
  jwt.accessTokenExpires = Date.now() + (15 * 60 * 1000);
452
- debugLog('createAuthResponse', 'JWT created:', {
452
+ debugLog('createAuthResponse', 'JWT created (for handleJWTCallback):', {
453
453
  hasId: !!jwt.id,
454
454
  hasEmail: !!jwt.email,
455
455
  hasRole: !!jwt.role,
456
456
  hasRefreshToken: !!jwt.refreshToken,
457
457
  });
458
- // 3. NextAuth session cookie 생성
459
- const nextAuthToken = await encodeNextAuthToken(jwt, secret);
460
- debugLog('createAuthResponse', 'NextAuth session token encoded:', {
461
- tokenLength: nextAuthToken.length,
462
- tokenPrefix: nextAuthToken.substring(0, 30) + '...',
463
- jwtId: jwt.id,
464
- jwtEmail: jwt.email?.substring(0, 20) + '...',
465
- });
466
- // 4. Response 생성 (HTTP 302 리다이렉트 사용)
458
+ // 3. Response 생성 (HTTP 302 리다이렉트 사용)
467
459
  const { NextResponse: NextResponseClass } = await getNextServer();
468
460
  // redirectPath가 있으면 302 리다이렉트, 없으면 200 OK
469
461
  const response = redirectPath
470
462
  ? NextResponseClass.redirect(new URL(redirectPath, req.url), { status: 302 })
471
463
  : NextResponseClass.json({ success: true, message: text || 'Authentication successful' }, { status: 200 });
472
- // 4. NextAuth session cookie 설정
473
- const nextAuthCookieName = isProduction
474
- ? '__Secure-next-auth.session-token'
475
- : 'next-auth.session-token';
476
- const cookieOptions = {
477
- httpOnly: true,
478
- secure: isProduction,
479
- sameSite: isProduction ? 'none' : 'lax',
480
- path: '/',
481
- maxAge: 30 * 24 * 60 * 60, // 30일
482
- };
483
- if (cookieDomain) {
484
- cookieOptions.domain = cookieDomain;
485
- }
486
- response.cookies.set(nextAuthCookieName, nextAuthToken, cookieOptions);
487
- debugLog('createAuthResponse', 'NextAuth session cookie set:', {
488
- name: nextAuthCookieName,
489
- valueLength: nextAuthToken.length,
490
- ...cookieOptions,
491
- });
492
- // 5. 커스텀 토큰 쿠키 설정
464
+ // 4. 커스텀 토큰 쿠키만 설정 (NextAuth 쿠키는 handleJWTCallback에서 생성됨)
493
465
  if (refreshToken) {
494
466
  setCustomTokens(response, accessToken, refreshToken, {
495
467
  cookiePrefix,
@@ -654,33 +626,12 @@ async function verifyAndRefreshToken(req, secret, options) {
654
626
  catch {
655
627
  // 토큰 검증 실패
656
628
  }
657
- debugLog('verifyAndRefreshToken', 'Updating cookies without redirect...');
658
- // NextResponse.next()를 생성하고 쿠키만 설정
629
+ debugLog('verifyAndRefreshToken', 'Updating custom cookies only (NextAuth will handle session)...');
630
+ // NextResponse.next()를 생성하고 커스텀 토큰만 설정
631
+ // NextAuth 쿠키는 생성하지 않음 - NextAuth가 자체적으로 처리하도록 함
659
632
  const { NextResponse: NextResponseClass } = await getNextServer();
660
633
  const response = NextResponseClass.next();
661
- // NextAuth JWT 생성
662
- const jwt = createNextAuthJWT(payload, serviceId);
663
- if (newRefreshToken) {
664
- jwt.refreshToken = newRefreshToken;
665
- }
666
- jwt.accessTokenExpires = Date.now() + (15 * 60 * 1000);
667
- // NextAuth 세션 쿠키 설정
668
- const nextAuthToken = await encodeNextAuthToken(jwt, secret);
669
- const nextAuthCookieName = isProduction
670
- ? '__Secure-next-auth.session-token'
671
- : 'next-auth.session-token';
672
- const cookieOptions = {
673
- httpOnly: true,
674
- secure: isProduction,
675
- sameSite: isProduction ? 'none' : 'lax',
676
- path: '/',
677
- maxAge: 30 * 24 * 60 * 60,
678
- };
679
- if (cookieDomain) {
680
- cookieOptions.domain = cookieDomain;
681
- }
682
- response.cookies.set(nextAuthCookieName, nextAuthToken, cookieOptions);
683
- // 커스텀 토큰 쿠키 설정
634
+ // 커스텀 토큰 쿠키만 설정
684
635
  if (newRefreshToken) {
685
636
  setCustomTokens(response, refreshResult.accessToken, newRefreshToken, {
686
637
  cookiePrefix,
@@ -695,7 +646,7 @@ async function verifyAndRefreshToken(req, secret, options) {
695
646
  cookieDomain,
696
647
  });
697
648
  }
698
- debugLog('verifyAndRefreshToken', 'Cookies updated, continuing with current request');
649
+ debugLog('verifyAndRefreshToken', 'Custom cookies updated, NextAuth will pick them up via handleJWTCallback');
699
650
  return { isValid: true, response, payload };
700
651
  }
701
652
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkingcat/auth-utils",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
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",