@thinkingcat/auth-utils 1.0.25 → 1.0.27
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.d.ts +2 -0
- package/dist/index.js +32 -12
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -130,11 +130,13 @@ export declare function encodeNextAuthToken(jwt: JWT, secret: string, maxAge?: n
|
|
|
130
130
|
export declare function setCustomTokens(response: ResponseLike, accessToken: string, refreshToken: string, options?: {
|
|
131
131
|
cookiePrefix?: string;
|
|
132
132
|
isProduction?: boolean;
|
|
133
|
+
cookieDomain?: string;
|
|
133
134
|
}): void;
|
|
134
135
|
export declare function setCustomTokens(response: ResponseLike, accessToken: string, options?: {
|
|
135
136
|
refreshToken?: string;
|
|
136
137
|
cookiePrefix?: string;
|
|
137
138
|
isProduction?: boolean;
|
|
139
|
+
cookieDomain?: string;
|
|
138
140
|
}): void;
|
|
139
141
|
/**
|
|
140
142
|
* NextAuth 세션 토큰만 설정
|
package/dist/index.js
CHANGED
|
@@ -259,15 +259,17 @@ function setCustomTokens(response, accessToken, optionsOrRefreshToken, options)
|
|
|
259
259
|
let refreshTokenValue;
|
|
260
260
|
let cookiePrefix;
|
|
261
261
|
let isProduction;
|
|
262
|
+
let cookieDomain;
|
|
262
263
|
if (typeof optionsOrRefreshToken === 'string') {
|
|
263
264
|
// 기존 방식: refreshToken이 문자열로 전달된 경우
|
|
264
265
|
refreshTokenValue = optionsOrRefreshToken;
|
|
265
|
-
const { cookiePrefix: prefix, isProduction: prod = false, } = options || {};
|
|
266
|
+
const { cookiePrefix: prefix, isProduction: prod = false, cookieDomain: domain, } = options || {};
|
|
266
267
|
if (!prefix) {
|
|
267
268
|
throw new Error('cookiePrefix is required');
|
|
268
269
|
}
|
|
269
270
|
cookiePrefix = prefix;
|
|
270
271
|
isProduction = prod;
|
|
272
|
+
cookieDomain = domain;
|
|
271
273
|
}
|
|
272
274
|
else {
|
|
273
275
|
// 새로운 방식: options 객체로 전달된 경우
|
|
@@ -278,26 +280,42 @@ function setCustomTokens(response, accessToken, optionsOrRefreshToken, options)
|
|
|
278
280
|
}
|
|
279
281
|
cookiePrefix = opts.cookiePrefix;
|
|
280
282
|
isProduction = opts.isProduction || false;
|
|
283
|
+
cookieDomain = opts.cookieDomain;
|
|
281
284
|
}
|
|
282
|
-
//
|
|
283
|
-
const
|
|
284
|
-
response.cookies.delete(accessTokenName);
|
|
285
|
-
response.cookies.set(accessTokenName, accessToken, {
|
|
285
|
+
// 쿠키 옵션 생성
|
|
286
|
+
const cookieOptions = {
|
|
286
287
|
httpOnly: true,
|
|
287
288
|
secure: isProduction,
|
|
288
289
|
sameSite: isProduction ? 'none' : 'lax',
|
|
289
|
-
maxAge: 15 * 60, // 15분
|
|
290
290
|
path: '/',
|
|
291
|
+
maxAge: 15 * 60, // access token: 15분
|
|
292
|
+
};
|
|
293
|
+
if (cookieDomain) {
|
|
294
|
+
cookieOptions.domain = cookieDomain;
|
|
295
|
+
}
|
|
296
|
+
// access_token 설정
|
|
297
|
+
const accessTokenName = `${cookiePrefix}_access_token`;
|
|
298
|
+
response.cookies.delete(accessTokenName);
|
|
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,
|
|
291
306
|
});
|
|
292
307
|
// refresh_token 설정 (있는 경우)
|
|
293
308
|
if (refreshTokenValue) {
|
|
294
309
|
const refreshTokenName = `${cookiePrefix}_refresh_token`;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
310
|
+
const refreshCookieOptions = {
|
|
311
|
+
...cookieOptions,
|
|
312
|
+
maxAge: 30 * 24 * 60 * 60, // refresh token: 30일
|
|
313
|
+
};
|
|
314
|
+
response.cookies.set(refreshTokenName, refreshTokenValue, refreshCookieOptions);
|
|
315
|
+
debugLog('setCustomTokens', `Set ${refreshTokenName} cookie:`, {
|
|
316
|
+
hasValue: !!refreshTokenValue,
|
|
317
|
+
maxAge: refreshCookieOptions.maxAge,
|
|
318
|
+
domain: refreshCookieOptions.domain,
|
|
301
319
|
});
|
|
302
320
|
}
|
|
303
321
|
}
|
|
@@ -468,12 +486,14 @@ async function createAuthResponse(accessToken, secret, options) {
|
|
|
468
486
|
setCustomTokens(response, accessToken, refreshToken, {
|
|
469
487
|
cookiePrefix,
|
|
470
488
|
isProduction,
|
|
489
|
+
cookieDomain,
|
|
471
490
|
});
|
|
472
491
|
}
|
|
473
492
|
else {
|
|
474
493
|
setCustomTokens(response, accessToken, {
|
|
475
494
|
cookiePrefix,
|
|
476
495
|
isProduction,
|
|
496
|
+
cookieDomain,
|
|
477
497
|
});
|
|
478
498
|
}
|
|
479
499
|
debugLog('createAuthResponse', 'Custom tokens set successfully');
|
package/package.json
CHANGED