@thinkingcat/auth-utils 1.0.30 → 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.
Files changed (2) hide show
  1. package/dist/index.js +42 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -651,20 +651,48 @@ async function verifyAndRefreshToken(req, secret, options) {
651
651
  catch {
652
652
  // 토큰 검증 실패
653
653
  }
654
- debugLog('verifyAndRefreshToken', 'Creating auth response...');
655
- // 현재 경로로 리다이렉트하여 새로운 쿠키로 다시 요청하도록 함
656
- const currentPath = req.nextUrl.pathname + req.nextUrl.search;
657
- const response = await createAuthResponse(refreshResult.accessToken, secret, {
658
- req,
659
- refreshToken: newRefreshToken,
660
- redirectPath: currentPath,
661
- text: text || serviceId,
662
- cookiePrefix,
663
- isProduction,
664
- cookieDomain,
665
- serviceId,
666
- licenseKey: options.licenseKey,
667
- });
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');
668
696
  return { isValid: true, response, payload };
669
697
  }
670
698
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkingcat/auth-utils",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
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",