@thinkingcat/auth-utils 1.0.43 → 1.0.45
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 +20 -50
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -460,33 +460,22 @@ async function createAuthResponse(accessToken, secret, options) {
|
|
|
460
460
|
const response = redirectPath
|
|
461
461
|
? NextResponseClass.redirect(new URL(redirectPath, req.url), { status: 302 })
|
|
462
462
|
: NextResponseClass.json({ success: true, message: text || 'Authentication successful' }, { status: 200 });
|
|
463
|
-
// 4. NextAuth 세션 쿠키 생성
|
|
463
|
+
// 4. NextAuth 세션 쿠키 생성
|
|
464
|
+
// 주의: NextAuth는 세션 쿠키를 자동으로 관리하므로, 직접 설정하는 것이 문제를 일으킬 수 있습니다.
|
|
465
|
+
// 하지만 미들웨어에서는 NextAuth의 정상 플로우를 사용할 수 없으므로,
|
|
466
|
+
// NextAuth의 encode()와 decode()가 호환되도록 주의해야 합니다.
|
|
464
467
|
const nextAuthCookieName = isProduction
|
|
465
468
|
? '__Secure-next-auth.session-token'
|
|
466
469
|
: 'next-auth.session-token';
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
if (cookieDomain) {
|
|
477
|
-
cookieOptions.domain = cookieDomain;
|
|
478
|
-
}
|
|
479
|
-
response.cookies.set(nextAuthCookieName, nextAuthToken, cookieOptions);
|
|
480
|
-
debugLog('createAuthResponse', 'NextAuth session cookie set:', {
|
|
481
|
-
name: nextAuthCookieName,
|
|
482
|
-
valueLength: nextAuthToken.length,
|
|
483
|
-
hasRefreshToken: !!refreshToken,
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
catch (error) {
|
|
487
|
-
debugError('createAuthResponse', 'Failed to set NextAuth cookie:', error);
|
|
488
|
-
// NextAuth 쿠키 실패해도 커스텀 토큰으로는 작동 가능
|
|
489
|
-
}
|
|
470
|
+
// NextAuth 세션 쿠키 설정을 건너뛰고 커스텀 토큰만 사용
|
|
471
|
+
// NextAuth는 JWT 콜백을 통해 자동으로 세션 쿠키를 생성하므로,
|
|
472
|
+
// 미들웨어에서 직접 설정하면 NextAuth가 디코딩할 수 없는 경우가 있습니다.
|
|
473
|
+
// 따라서 커스텀 토큰만 설정하고, NextAuth 세션은 JWT 콜백에서 처리하도록 합니다.
|
|
474
|
+
debugLog('createAuthResponse', 'Skipping NextAuth session cookie - will be handled by NextAuth JWT callback', {
|
|
475
|
+
name: nextAuthCookieName,
|
|
476
|
+
hasJWT: !!jwt,
|
|
477
|
+
jwtId: jwt?.id,
|
|
478
|
+
});
|
|
490
479
|
// 5. 커스텀 토큰 쿠키 설정
|
|
491
480
|
if (refreshToken) {
|
|
492
481
|
setCustomTokens(response, accessToken, refreshToken, {
|
|
@@ -667,32 +656,13 @@ async function verifyAndRefreshToken(req, secret, options) {
|
|
|
667
656
|
jwt.refreshToken = newRefreshToken;
|
|
668
657
|
}
|
|
669
658
|
jwt.accessTokenExpires = Date.now() + (15 * 60 * 1000);
|
|
670
|
-
// NextAuth 세션 쿠키 생성
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
httpOnly: true,
|
|
678
|
-
secure: isProduction,
|
|
679
|
-
sameSite: isProduction ? 'none' : 'lax',
|
|
680
|
-
path: '/',
|
|
681
|
-
maxAge: 30 * 24 * 60 * 60,
|
|
682
|
-
};
|
|
683
|
-
if (cookieDomain) {
|
|
684
|
-
cookieOptions.domain = cookieDomain;
|
|
685
|
-
}
|
|
686
|
-
response.cookies.set(nextAuthCookieName, nextAuthToken, cookieOptions);
|
|
687
|
-
debugLog('verifyAndRefreshToken', 'NextAuth session cookie set:', {
|
|
688
|
-
name: nextAuthCookieName,
|
|
689
|
-
valueLength: nextAuthToken.length,
|
|
690
|
-
});
|
|
691
|
-
}
|
|
692
|
-
catch (error) {
|
|
693
|
-
debugError('verifyAndRefreshToken', 'Failed to set NextAuth cookie:', error);
|
|
694
|
-
// Continue even if NextAuth cookie fails
|
|
695
|
-
}
|
|
659
|
+
// 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
|
+
});
|
|
696
666
|
// 커스텀 토큰 쿠키 설정
|
|
697
667
|
if (newRefreshToken) {
|
|
698
668
|
setCustomTokens(response, refreshResult.accessToken, newRefreshToken, {
|
package/package.json
CHANGED