@thinkingcat/auth-utils 1.0.29 → 1.0.31
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 +42 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -651,18 +651,48 @@ async function verifyAndRefreshToken(req, secret, options) {
|
|
|
651
651
|
catch {
|
|
652
652
|
// 토큰 검증 실패
|
|
653
653
|
}
|
|
654
|
-
debugLog('verifyAndRefreshToken', '
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
654
|
+
debugLog('verifyAndRefreshToken', 'Updating cookies without redirect...');
|
|
655
|
+
// NextResponse.next()를 생성하고 쿠키만 설정
|
|
656
|
+
const { NextResponse: NextResponseClass } = await getNextServer();
|
|
657
|
+
const response = NextResponseClass.next();
|
|
658
|
+
// NextAuth JWT 생성
|
|
659
|
+
const jwt = createNextAuthJWT(payload, serviceId);
|
|
660
|
+
if (newRefreshToken) {
|
|
661
|
+
jwt.refreshToken = newRefreshToken;
|
|
662
|
+
}
|
|
663
|
+
jwt.accessTokenExpires = Date.now() + (15 * 60 * 1000);
|
|
664
|
+
// NextAuth 세션 쿠키 설정
|
|
665
|
+
const nextAuthToken = await encodeNextAuthToken(jwt, secret);
|
|
666
|
+
const nextAuthCookieName = isProduction
|
|
667
|
+
? '__Secure-next-auth.session-token'
|
|
668
|
+
: 'next-auth.session-token';
|
|
669
|
+
const cookieOptions = {
|
|
670
|
+
httpOnly: true,
|
|
671
|
+
secure: isProduction,
|
|
672
|
+
sameSite: isProduction ? 'none' : 'lax',
|
|
673
|
+
path: '/',
|
|
674
|
+
maxAge: 30 * 24 * 60 * 60,
|
|
675
|
+
};
|
|
676
|
+
if (cookieDomain) {
|
|
677
|
+
cookieOptions.domain = cookieDomain;
|
|
678
|
+
}
|
|
679
|
+
response.cookies.set(nextAuthCookieName, nextAuthToken, cookieOptions);
|
|
680
|
+
// 커스텀 토큰 쿠키 설정
|
|
681
|
+
if (newRefreshToken) {
|
|
682
|
+
setCustomTokens(response, refreshResult.accessToken, newRefreshToken, {
|
|
683
|
+
cookiePrefix,
|
|
684
|
+
isProduction,
|
|
685
|
+
cookieDomain,
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
setCustomTokens(response, refreshResult.accessToken, {
|
|
690
|
+
cookiePrefix,
|
|
691
|
+
isProduction,
|
|
692
|
+
cookieDomain,
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
debugLog('verifyAndRefreshToken', 'Cookies updated, continuing with current request');
|
|
666
696
|
return { isValid: true, response, payload };
|
|
667
697
|
}
|
|
668
698
|
catch (error) {
|
package/package.json
CHANGED