@thinkingcat/auth-utils 1.0.28 → 1.0.29

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 CHANGED
@@ -162,15 +162,19 @@ export declare function createRedirectHTML(redirectPath: string, text: string):
162
162
  * @param accessToken access token
163
163
  * @param secret JWT 서명에 사용할 secret key
164
164
  * @param options 추가 옵션
165
+ * @param options.req NextRequest 객체 (필수 - URL origin을 위해 필요)
165
166
  * @param options.refreshToken refresh token (선택)
166
- * @param options.redirectPath 리다이렉트할 경로 (기본값: 페이지 리로드)
167
- * @param options.text 리다이렉트 HTML에 표시할 텍스트 (선택사항)
167
+ * @param options.redirectPath 리다이렉트할 경로 (HTTP 302 리다이렉트 사용)
168
+ * @param options.text 응답 메시지 텍스트 (선택사항)
168
169
  * @param options.cookiePrefix 쿠키 이름 접두사 (필수)
169
170
  * @param options.isProduction 프로덕션 환경 여부 (기본값: false)
170
171
  * @param options.cookieDomain 쿠키 도메인 (선택)
171
- * @returns NextResponse 객체
172
+ * @param options.serviceId 서비스 ID (필수)
173
+ * @param options.licenseKey 라이센스 키 (필수)
174
+ * @returns NextResponse 객체 (리다이렉트 또는 JSON 응답)
172
175
  */
173
176
  export declare function createAuthResponse(accessToken: string, secret: string, options: {
177
+ req: NextRequest;
174
178
  refreshToken?: string;
175
179
  redirectPath?: string;
176
180
  text?: string;
package/dist/index.js CHANGED
@@ -418,17 +418,20 @@ function createRedirectHTML(redirectPath, text) {
418
418
  * @param accessToken access token
419
419
  * @param secret JWT 서명에 사용할 secret key
420
420
  * @param options 추가 옵션
421
+ * @param options.req NextRequest 객체 (필수 - URL origin을 위해 필요)
421
422
  * @param options.refreshToken refresh token (선택)
422
- * @param options.redirectPath 리다이렉트할 경로 (기본값: 페이지 리로드)
423
- * @param options.text 리다이렉트 HTML에 표시할 텍스트 (선택사항)
423
+ * @param options.redirectPath 리다이렉트할 경로 (HTTP 302 리다이렉트 사용)
424
+ * @param options.text 응답 메시지 텍스트 (선택사항)
424
425
  * @param options.cookiePrefix 쿠키 이름 접두사 (필수)
425
426
  * @param options.isProduction 프로덕션 환경 여부 (기본값: false)
426
427
  * @param options.cookieDomain 쿠키 도메인 (선택)
427
- * @returns NextResponse 객체
428
+ * @param options.serviceId 서비스 ID (필수)
429
+ * @param options.licenseKey 라이센스 키 (필수)
430
+ * @returns NextResponse 객체 (리다이렉트 또는 JSON 응답)
428
431
  */
429
432
  async function createAuthResponse(accessToken, secret, options) {
430
433
  await checkLicenseKey(options.licenseKey);
431
- const { refreshToken, redirectPath, text, cookiePrefix, isProduction = false, cookieDomain, serviceId, } = options;
434
+ const { req, refreshToken, redirectPath, text, cookiePrefix, isProduction = false, cookieDomain, serviceId, } = options;
432
435
  // 1. 토큰 검증
433
436
  const tokenResult = await verifyToken(accessToken, secret);
434
437
  if (!tokenResult) {
@@ -457,19 +460,12 @@ async function createAuthResponse(accessToken, secret, options) {
457
460
  jwtId: jwt.id,
458
461
  jwtEmail: jwt.email?.substring(0, 20) + '...',
459
462
  });
460
- // 5. HTML 생성
461
- const displayText = text || serviceId;
462
- const html = redirectPath
463
- ? createRedirectHTML(redirectPath, displayText)
464
- : createRedirectHTML('', displayText).replace("window.location.href = ''", "window.location.reload()");
465
- // 6. Response 생성
463
+ // 4. Response 생성 (HTTP 302 리다이렉트 사용)
466
464
  const { NextResponse: NextResponseClass } = await getNextServer();
467
- const response = new NextResponseClass(html, {
468
- status: 200,
469
- headers: {
470
- 'Content-Type': 'text/html',
471
- },
472
- });
465
+ // redirectPath가 있으면 302 리다이렉트, 없으면 200 OK
466
+ const response = redirectPath
467
+ ? NextResponseClass.redirect(new URL(redirectPath, req.url), { status: 302 })
468
+ : NextResponseClass.json({ success: true, message: text || 'Authentication successful' }, { status: 200 });
473
469
  // 4. NextAuth session cookie 설정
474
470
  const nextAuthCookieName = isProduction
475
471
  ? '__Secure-next-auth.session-token'
@@ -657,6 +653,7 @@ async function verifyAndRefreshToken(req, secret, options) {
657
653
  }
658
654
  debugLog('verifyAndRefreshToken', 'Creating auth response...');
659
655
  const response = await createAuthResponse(refreshResult.accessToken, secret, {
656
+ req,
660
657
  refreshToken: newRefreshToken,
661
658
  redirectPath: '',
662
659
  text: text || serviceId,
@@ -1519,6 +1516,7 @@ async function handleMiddleware(req, config, options) {
1519
1516
  const redirectPath = config.rolePaths[tokenRole] || config.rolePaths[defaultRole] || '/admin';
1520
1517
  debugLog('handleMiddleware', `Creating auth response, redirect to: ${redirectPath}`);
1521
1518
  const response = await createAuthResponse(tokenParam, secret, {
1519
+ req,
1522
1520
  refreshToken: refreshToken || undefined,
1523
1521
  redirectPath,
1524
1522
  text: serviceId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkingcat/auth-utils",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
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",