@thinkingcat/auth-utils 1.0.26 → 1.0.28

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 +35 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -297,6 +297,13 @@ function setCustomTokens(response, accessToken, optionsOrRefreshToken, options)
297
297
  const accessTokenName = `${cookiePrefix}_access_token`;
298
298
  response.cookies.delete(accessTokenName);
299
299
  response.cookies.set(accessTokenName, accessToken, cookieOptions);
300
+ debugLog('setCustomTokens', `Set ${accessTokenName} cookie:`, {
301
+ hasValue: !!accessToken,
302
+ maxAge: cookieOptions.maxAge,
303
+ domain: cookieOptions.domain,
304
+ secure: cookieOptions.secure,
305
+ sameSite: cookieOptions.sameSite,
306
+ });
300
307
  // refresh_token 설정 (있는 경우)
301
308
  if (refreshTokenValue) {
302
309
  const refreshTokenName = `${cookiePrefix}_refresh_token`;
@@ -305,6 +312,11 @@ function setCustomTokens(response, accessToken, optionsOrRefreshToken, options)
305
312
  maxAge: 30 * 24 * 60 * 60, // refresh token: 30일
306
313
  };
307
314
  response.cookies.set(refreshTokenName, refreshTokenValue, refreshCookieOptions);
315
+ debugLog('setCustomTokens', `Set ${refreshTokenName} cookie:`, {
316
+ hasValue: !!refreshTokenValue,
317
+ maxAge: refreshCookieOptions.maxAge,
318
+ domain: refreshCookieOptions.domain,
319
+ });
308
320
  }
309
321
  }
310
322
  /**
@@ -439,7 +451,12 @@ async function createAuthResponse(accessToken, secret, options) {
439
451
  });
440
452
  // 3. NextAuth session cookie 생성
441
453
  const nextAuthToken = await encodeNextAuthToken(jwt, secret);
442
- debugLog('createAuthResponse', 'NextAuth session token encoded');
454
+ debugLog('createAuthResponse', 'NextAuth session token encoded:', {
455
+ tokenLength: nextAuthToken.length,
456
+ tokenPrefix: nextAuthToken.substring(0, 30) + '...',
457
+ jwtId: jwt.id,
458
+ jwtEmail: jwt.email?.substring(0, 20) + '...',
459
+ });
443
460
  // 5. HTML 생성
444
461
  const displayText = text || serviceId;
445
462
  const html = redirectPath
@@ -468,7 +485,11 @@ async function createAuthResponse(accessToken, secret, options) {
468
485
  cookieOptions.domain = cookieDomain;
469
486
  }
470
487
  response.cookies.set(nextAuthCookieName, nextAuthToken, cookieOptions);
471
- debugLog('createAuthResponse', 'NextAuth session cookie set:', nextAuthCookieName);
488
+ debugLog('createAuthResponse', 'NextAuth session cookie set:', {
489
+ name: nextAuthCookieName,
490
+ valueLength: nextAuthToken.length,
491
+ ...cookieOptions,
492
+ });
472
493
  // 5. 커스텀 토큰 쿠키 설정
473
494
  if (refreshToken) {
474
495
  setCustomTokens(response, accessToken, refreshToken, {
@@ -1236,7 +1257,14 @@ async function verifyAndRefreshTokenWithNextAuth(req, nextAuthToken, secret, opt
1236
1257
  const nextAuthSessionTokenCookieName = isProduction
1237
1258
  ? '__Secure-next-auth.session-token'
1238
1259
  : 'next-auth.session-token';
1239
- const hasNextAuthSessionTokenCookie = !!req.cookies.get(nextAuthSessionTokenCookieName)?.value;
1260
+ const nextAuthCookieValue = req.cookies.get(nextAuthSessionTokenCookieName)?.value;
1261
+ const hasNextAuthSessionTokenCookie = !!nextAuthCookieValue;
1262
+ debugLog('verifyAndRefreshTokenWithNextAuth', 'NextAuth cookie check:', {
1263
+ cookieName: nextAuthSessionTokenCookieName,
1264
+ hasCookie: hasNextAuthSessionTokenCookie,
1265
+ cookieLength: nextAuthCookieValue?.length || 0,
1266
+ cookiePrefix: nextAuthCookieValue?.substring(0, 30) + '...' || 'none',
1267
+ });
1240
1268
  // NextAuth 토큰 확인
1241
1269
  const hasValidNextAuthToken = nextAuthToken && isValidToken(nextAuthToken);
1242
1270
  // Access token 확인
@@ -1418,13 +1446,16 @@ async function handleMiddleware(req, config, options) {
1418
1446
  let token = null;
1419
1447
  if (getNextAuthToken) {
1420
1448
  token = await getNextAuthToken(req);
1449
+ debugLog('handleMiddleware', 'Custom getNextAuthToken result:', { hasToken: !!token });
1421
1450
  }
1422
1451
  else {
1423
1452
  try {
1424
1453
  const { getToken } = await Promise.resolve().then(() => __importStar(require('next-auth/jwt')));
1425
1454
  token = await getToken({ req, secret });
1455
+ debugLog('handleMiddleware', 'getToken result:', { hasToken: !!token });
1426
1456
  }
1427
- catch {
1457
+ catch (error) {
1458
+ debugLog('handleMiddleware', 'getToken failed:', error);
1428
1459
  // NextAuth가 없으면 null 유지
1429
1460
  }
1430
1461
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkingcat/auth-utils",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
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",