@thinkingcat/auth-utils 1.0.22 → 1.0.23
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 +27 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -419,14 +419,21 @@ async function createAuthResponse(accessToken, secret, options) {
|
|
|
419
419
|
const { payload } = tokenResult;
|
|
420
420
|
// 2. NextAuth JWT 생성
|
|
421
421
|
const jwt = createNextAuthJWT(payload, serviceId);
|
|
422
|
+
// refreshToken 추가
|
|
423
|
+
if (refreshToken) {
|
|
424
|
+
jwt.refreshToken = refreshToken;
|
|
425
|
+
}
|
|
426
|
+
// accessTokenExpires 추가 (15분)
|
|
427
|
+
jwt.accessTokenExpires = Date.now() + (15 * 60 * 1000);
|
|
422
428
|
debugLog('createAuthResponse', 'JWT created:', {
|
|
423
429
|
hasId: !!jwt.id,
|
|
424
430
|
hasEmail: !!jwt.email,
|
|
425
431
|
hasRole: !!jwt.role,
|
|
432
|
+
hasRefreshToken: !!jwt.refreshToken,
|
|
426
433
|
});
|
|
427
|
-
// 3. NextAuth
|
|
428
|
-
|
|
429
|
-
debugLog('createAuthResponse', '
|
|
434
|
+
// 3. NextAuth session cookie 생성
|
|
435
|
+
const nextAuthToken = await encodeNextAuthToken(jwt, secret);
|
|
436
|
+
debugLog('createAuthResponse', 'NextAuth session token encoded');
|
|
430
437
|
// 5. HTML 생성
|
|
431
438
|
const displayText = text || serviceId;
|
|
432
439
|
const html = redirectPath
|
|
@@ -440,7 +447,23 @@ async function createAuthResponse(accessToken, secret, options) {
|
|
|
440
447
|
'Content-Type': 'text/html',
|
|
441
448
|
},
|
|
442
449
|
});
|
|
443
|
-
// 4.
|
|
450
|
+
// 4. NextAuth session cookie 설정
|
|
451
|
+
const nextAuthCookieName = isProduction
|
|
452
|
+
? '__Secure-next-auth.session-token'
|
|
453
|
+
: 'next-auth.session-token';
|
|
454
|
+
const cookieOptions = {
|
|
455
|
+
httpOnly: true,
|
|
456
|
+
secure: isProduction,
|
|
457
|
+
sameSite: isProduction ? 'none' : 'lax',
|
|
458
|
+
path: '/',
|
|
459
|
+
maxAge: 30 * 24 * 60 * 60, // 30일
|
|
460
|
+
};
|
|
461
|
+
if (cookieDomain) {
|
|
462
|
+
cookieOptions.domain = cookieDomain;
|
|
463
|
+
}
|
|
464
|
+
response.cookies.set(nextAuthCookieName, nextAuthToken, cookieOptions);
|
|
465
|
+
debugLog('createAuthResponse', 'NextAuth session cookie set:', nextAuthCookieName);
|
|
466
|
+
// 5. 커스텀 토큰 쿠키 설정
|
|
444
467
|
if (refreshToken) {
|
|
445
468
|
setCustomTokens(response, accessToken, refreshToken, {
|
|
446
469
|
cookiePrefix,
|
package/package.json
CHANGED