@thinkingcat/auth-utils 1.0.5 → 1.0.6
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 +29 -0
- package/dist/index.js +66 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -291,6 +291,29 @@ export interface RoleAccessConfig {
|
|
|
291
291
|
allowedRoles?: string[];
|
|
292
292
|
};
|
|
293
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* 미들웨어 설정 인터페이스
|
|
296
|
+
*/
|
|
297
|
+
export interface MiddlewareConfig {
|
|
298
|
+
/** 공개 접근 가능한 경로 배열 */
|
|
299
|
+
publicPaths?: string[];
|
|
300
|
+
/** 구독이 필요한 경로 배열 */
|
|
301
|
+
subscriptionRequiredPaths?: string[];
|
|
302
|
+
/** 구독 상태 확인을 제외할 API 경로 배열 */
|
|
303
|
+
subscriptionExemptApiPaths?: string[];
|
|
304
|
+
/** 인증 관련 API 경로 배열 */
|
|
305
|
+
authApiPaths?: string[];
|
|
306
|
+
/** 역할별 대시보드 경로 객체 */
|
|
307
|
+
rolePaths?: Record<string, string>;
|
|
308
|
+
/** 역할 기반 접근 제어 설정 */
|
|
309
|
+
roleAccessConfig?: RoleAccessConfig;
|
|
310
|
+
/** 서비스 ID */
|
|
311
|
+
serviceId?: string;
|
|
312
|
+
/** 시스템 관리자 역할명 (기본값: 'SYSTEM_ADMIN') */
|
|
313
|
+
systemAdminRole?: string;
|
|
314
|
+
/** 에러 페이지 경로 (기본값: '/error') */
|
|
315
|
+
errorPath?: string;
|
|
316
|
+
}
|
|
294
317
|
export declare function checkRoleAccess(pathname: string, role: string, roleConfig: RoleAccessConfig): {
|
|
295
318
|
allowed: boolean;
|
|
296
319
|
message?: string;
|
|
@@ -404,3 +427,9 @@ export declare function verifyAndRefreshTokenWithNextAuth(req: NextRequest, next
|
|
|
404
427
|
error?: string;
|
|
405
428
|
payload?: JWTPayload;
|
|
406
429
|
}>;
|
|
430
|
+
/**
|
|
431
|
+
* 기본 미들웨어 설정을 생성하는 함수
|
|
432
|
+
* @param config 커스텀 설정 (선택사항)
|
|
433
|
+
* @returns 미들웨어 설정 객체
|
|
434
|
+
*/
|
|
435
|
+
export declare function createMiddlewareConfig(config?: Partial<MiddlewareConfig>): Required<Omit<MiddlewareConfig, 'serviceId'>> & Pick<MiddlewareConfig, 'serviceId'>;
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ exports.isApiPath = isApiPath;
|
|
|
28
28
|
exports.isProtectedApiPath = isProtectedApiPath;
|
|
29
29
|
exports.checkAuthentication = checkAuthentication;
|
|
30
30
|
exports.verifyAndRefreshTokenWithNextAuth = verifyAndRefreshTokenWithNextAuth;
|
|
31
|
+
exports.createMiddlewareConfig = createMiddlewareConfig;
|
|
31
32
|
const jwt_1 = require("next-auth/jwt");
|
|
32
33
|
const jose_1 = require("jose");
|
|
33
34
|
const server_1 = require("next/server");
|
|
@@ -726,3 +727,68 @@ async function verifyAndRefreshTokenWithNextAuth(req, nextAuthToken, secret, opt
|
|
|
726
727
|
const authCheck = await verifyAndRefreshToken(req, secret, options);
|
|
727
728
|
return authCheck;
|
|
728
729
|
}
|
|
730
|
+
/**
|
|
731
|
+
* 기본 미들웨어 설정을 생성하는 함수
|
|
732
|
+
* @param config 커스텀 설정 (선택사항)
|
|
733
|
+
* @returns 미들웨어 설정 객체
|
|
734
|
+
*/
|
|
735
|
+
function createMiddlewareConfig(config) {
|
|
736
|
+
const defaultConfig = {
|
|
737
|
+
publicPaths: [
|
|
738
|
+
'/robots.txt',
|
|
739
|
+
'/sitemap.xml',
|
|
740
|
+
'/ads.txt',
|
|
741
|
+
'/images',
|
|
742
|
+
'/login',
|
|
743
|
+
'/register',
|
|
744
|
+
'/forgot-password',
|
|
745
|
+
'/reset-password',
|
|
746
|
+
'/about',
|
|
747
|
+
'/pricing',
|
|
748
|
+
'/support',
|
|
749
|
+
'/terms',
|
|
750
|
+
'/privacy',
|
|
751
|
+
'/refund',
|
|
752
|
+
'/error',
|
|
753
|
+
],
|
|
754
|
+
subscriptionRequiredPaths: [
|
|
755
|
+
'/admin',
|
|
756
|
+
'/teacher',
|
|
757
|
+
'/student',
|
|
758
|
+
'/personal',
|
|
759
|
+
],
|
|
760
|
+
subscriptionExemptApiPaths: [
|
|
761
|
+
'/api/auth',
|
|
762
|
+
'/api/sso',
|
|
763
|
+
'/api/admin/subscription',
|
|
764
|
+
'/api/admin/payment-methods',
|
|
765
|
+
],
|
|
766
|
+
authApiPaths: [
|
|
767
|
+
'/api/auth/send-verification',
|
|
768
|
+
'/api/auth/verify-code',
|
|
769
|
+
'/api/auth/verify-user',
|
|
770
|
+
'/api/auth/select-academy',
|
|
771
|
+
],
|
|
772
|
+
rolePaths: {
|
|
773
|
+
SYSTEM_ADMIN: '/system',
|
|
774
|
+
ADMIN: '/admin',
|
|
775
|
+
TEACHER: '/teacher',
|
|
776
|
+
STUDENT: '/student',
|
|
777
|
+
},
|
|
778
|
+
roleAccessConfig: {},
|
|
779
|
+
systemAdminRole: 'SYSTEM_ADMIN',
|
|
780
|
+
errorPath: '/error',
|
|
781
|
+
serviceId: config?.serviceId,
|
|
782
|
+
};
|
|
783
|
+
// 커스텀 설정으로 병합
|
|
784
|
+
return {
|
|
785
|
+
...defaultConfig,
|
|
786
|
+
...config,
|
|
787
|
+
publicPaths: config?.publicPaths || defaultConfig.publicPaths,
|
|
788
|
+
subscriptionRequiredPaths: config?.subscriptionRequiredPaths || defaultConfig.subscriptionRequiredPaths,
|
|
789
|
+
subscriptionExemptApiPaths: config?.subscriptionExemptApiPaths || defaultConfig.subscriptionExemptApiPaths,
|
|
790
|
+
authApiPaths: config?.authApiPaths || defaultConfig.authApiPaths,
|
|
791
|
+
rolePaths: config?.rolePaths || defaultConfig.rolePaths,
|
|
792
|
+
roleAccessConfig: config?.roleAccessConfig || defaultConfig.roleAccessConfig,
|
|
793
|
+
};
|
|
794
|
+
}
|