@thinkingcat/auth-utils 1.0.39 → 1.0.40

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 +6 -28
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -448,44 +448,22 @@ async function createAuthResponse(accessToken, secret, options) {
448
448
  }
449
449
  // accessTokenExpires 추가 (15분)
450
450
  jwt.accessTokenExpires = Date.now() + (15 * 60 * 1000);
451
- debugLog('createAuthResponse', 'JWT created:', {
451
+ debugLog('createAuthResponse', 'JWT prepared (NextAuth will create session from custom tokens):', {
452
452
  hasId: !!jwt.id,
453
453
  hasEmail: !!jwt.email,
454
454
  hasRole: !!jwt.role,
455
455
  hasRefreshToken: !!jwt.refreshToken,
456
456
  });
457
- // 3. NextAuth 세션 쿠키 생성 (NextAuth encode() 우선 사용)
458
- const nextAuthToken = await encodeNextAuthToken(jwt, secret);
459
- debugLog('createAuthResponse', 'NextAuth session token encoded:', {
460
- tokenLength: nextAuthToken.length,
461
- });
462
- // 4. Response 생성 (HTTP 302 리다이렉트 사용)
457
+ // 3. Response 생성 (HTTP 302 리다이렉트 사용)
463
458
  const { NextResponse: NextResponseClass } = await getNextServer();
464
459
  // redirectPath가 있으면 302 리다이렉트, 없으면 200 OK
465
460
  const response = redirectPath
466
461
  ? NextResponseClass.redirect(new URL(redirectPath, req.url), { status: 302 })
467
462
  : NextResponseClass.json({ success: true, message: text || 'Authentication successful' }, { status: 200 });
468
- // 5. NextAuth 세션 쿠키 설정
469
- const nextAuthCookieName = isProduction
470
- ? '__Secure-next-auth.session-token'
471
- : 'next-auth.session-token';
472
- const cookieOptions = {
473
- httpOnly: true,
474
- secure: isProduction,
475
- sameSite: isProduction ? 'none' : 'lax',
476
- path: '/',
477
- maxAge: 30 * 24 * 60 * 60, // 30일
478
- };
479
- if (cookieDomain) {
480
- cookieOptions.domain = cookieDomain;
481
- }
482
- response.cookies.set(nextAuthCookieName, nextAuthToken, cookieOptions);
483
- debugLog('createAuthResponse', 'NextAuth session cookie set:', {
484
- name: nextAuthCookieName,
485
- valueLength: nextAuthToken.length,
486
- ...cookieOptions,
487
- });
488
- // 6. 커스텀 토큰 쿠키 설정
463
+ // 4. 처음 로그인 시에는 NextAuth 쿠키를 생성하지 않음
464
+ // Edge Runtime에서 생성한 NextAuth 쿠키는 Node.js Runtime에서 디코드 실패
465
+ // 대신 커스텀 토큰만 설정하고, handleJWTCallback이 이를 읽어서 세션 생성
466
+ // 5. 커스텀 토큰 쿠키 설정
489
467
  if (refreshToken) {
490
468
  setCustomTokens(response, accessToken, refreshToken, {
491
469
  cookiePrefix,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkingcat/auth-utils",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
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",