ecrs-auth-core 1.0.35 → 1.0.37
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/auth.module.d.ts +2 -2
- package/dist/auth.module.js +24 -26
- package/dist/guards/module.guard.js +49 -27
- package/package.json +1 -1
package/dist/auth.module.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DynamicModule } from
|
|
2
|
-
import { AuthCoreOptions } from
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { AuthCoreOptions } from './interfaces/auth-core-options.interface';
|
|
3
3
|
export declare const AUTH_CORE_OPTIONS = "AUTH_CORE_OPTIONS";
|
|
4
4
|
export declare class AuthCoreModule {
|
|
5
5
|
static registerAsync(options: {
|
package/dist/auth.module.js
CHANGED
|
@@ -19,7 +19,7 @@ const roles_guard_1 = require("./guards/roles.guard");
|
|
|
19
19
|
const feature_guard_1 = require("./guards/feature.guard");
|
|
20
20
|
const route_guard_1 = require("./guards/route.guard");
|
|
21
21
|
const permission_guard_1 = require("./guards/permission.guard");
|
|
22
|
-
exports.AUTH_CORE_OPTIONS =
|
|
22
|
+
exports.AUTH_CORE_OPTIONS = 'AUTH_CORE_OPTIONS';
|
|
23
23
|
// @Global()
|
|
24
24
|
// @Module({})
|
|
25
25
|
// export class AuthCoreModule {
|
|
@@ -34,31 +34,24 @@ exports.AUTH_CORE_OPTIONS = "AUTH_CORE_OPTIONS";
|
|
|
34
34
|
// };
|
|
35
35
|
// return {
|
|
36
36
|
// module: AuthCoreModule,
|
|
37
|
-
// imports: [
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
// console.log(
|
|
44
|
-
// "🔐 JWT Secret from AUTH_CORE_OPTIONS:",
|
|
45
|
-
// options.jwtSecret
|
|
46
|
-
// );
|
|
47
|
-
// console.log("⏳ JWT Expiry:", options.jwtExpiresIn);
|
|
37
|
+
// imports: [
|
|
38
|
+
// JwtModule.registerAsync({
|
|
39
|
+
// inject: options.inject,
|
|
40
|
+
// useFactory: async (...args: any[]) => {
|
|
41
|
+
// const config = await options.useFactory(...args);
|
|
42
|
+
// console.log("🔐 JWT Secret from AUTH_CORE_OPTIONS:", config.jwtSecret);
|
|
43
|
+
// console.log("⏳ JWT Expiry:", config.jwtExpiresIn);
|
|
48
44
|
// return {
|
|
49
|
-
// secret:
|
|
50
|
-
// signOptions: { expiresIn:
|
|
45
|
+
// secret: config.jwtSecret,
|
|
46
|
+
// signOptions: { expiresIn: config.jwtExpiresIn },
|
|
51
47
|
// };
|
|
52
48
|
// },
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
// useFactory: async (jwtOptions: any) => JwtModule.register(jwtOptions),
|
|
58
|
-
// inject: ["ASYNC_JWT_OPTIONS"],
|
|
59
|
-
// },
|
|
49
|
+
// }),
|
|
50
|
+
// ],
|
|
51
|
+
// providers: [
|
|
52
|
+
// asyncProvider,
|
|
60
53
|
// {
|
|
61
|
-
// provide:
|
|
54
|
+
// provide: 'MODULE_CONFIG',
|
|
62
55
|
// useFactory: (options: AuthCoreOptions) => options.moduleConfig || {},
|
|
63
56
|
// inject: [AUTH_CORE_OPTIONS],
|
|
64
57
|
// },
|
|
@@ -81,6 +74,7 @@ exports.AUTH_CORE_OPTIONS = "AUTH_CORE_OPTIONS";
|
|
|
81
74
|
// FeatureGuard,
|
|
82
75
|
// RouteGuard,
|
|
83
76
|
// PermissionGuard,
|
|
77
|
+
// JwtModule,
|
|
84
78
|
// ],
|
|
85
79
|
// };
|
|
86
80
|
// }
|
|
@@ -99,8 +93,8 @@ let AuthCoreModule = AuthCoreModule_1 = class AuthCoreModule {
|
|
|
99
93
|
inject: options.inject,
|
|
100
94
|
useFactory: async (...args) => {
|
|
101
95
|
const config = await options.useFactory(...args);
|
|
102
|
-
console.log(
|
|
103
|
-
console.log(
|
|
96
|
+
console.log('🔐 JWT Secret from AUTH_CORE_OPTIONS:', config.jwtSecret);
|
|
97
|
+
console.log('⏳ JWT Expiry:', config.jwtExpiresIn);
|
|
104
98
|
return {
|
|
105
99
|
secret: config.jwtSecret,
|
|
106
100
|
signOptions: { expiresIn: config.jwtExpiresIn },
|
|
@@ -112,7 +106,7 @@ let AuthCoreModule = AuthCoreModule_1 = class AuthCoreModule {
|
|
|
112
106
|
asyncProvider,
|
|
113
107
|
{
|
|
114
108
|
provide: 'MODULE_CONFIG',
|
|
115
|
-
useFactory: (
|
|
109
|
+
useFactory: (opts) => opts.moduleConfig || {},
|
|
116
110
|
inject: [exports.AUTH_CORE_OPTIONS],
|
|
117
111
|
},
|
|
118
112
|
auth_service_1.AuthService,
|
|
@@ -126,6 +120,11 @@ let AuthCoreModule = AuthCoreModule_1 = class AuthCoreModule {
|
|
|
126
120
|
],
|
|
127
121
|
controllers: [auth_controller_1.AuthController],
|
|
128
122
|
exports: [
|
|
123
|
+
// ⬇️ export these so Superadmin can resolve guard deps
|
|
124
|
+
exports.AUTH_CORE_OPTIONS,
|
|
125
|
+
'MODULE_CONFIG',
|
|
126
|
+
// optional but handy:
|
|
127
|
+
jwt_1.JwtModule,
|
|
129
128
|
auth_service_1.AuthService,
|
|
130
129
|
jwt_strategy_1.JwtStrategy,
|
|
131
130
|
jwt_guard_1.JwtAuthGuard,
|
|
@@ -134,7 +133,6 @@ let AuthCoreModule = AuthCoreModule_1 = class AuthCoreModule {
|
|
|
134
133
|
feature_guard_1.FeatureGuard,
|
|
135
134
|
route_guard_1.RouteGuard,
|
|
136
135
|
permission_guard_1.PermissionGuard,
|
|
137
|
-
jwt_1.JwtModule, // ✅ Re-export so JwtService works in consuming modules
|
|
138
136
|
],
|
|
139
137
|
};
|
|
140
138
|
}
|
|
@@ -1,36 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __decorate =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __decorate =
|
|
3
|
+
(this && this.__decorate) ||
|
|
4
|
+
function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length,
|
|
6
|
+
r =
|
|
7
|
+
c < 3
|
|
8
|
+
? target
|
|
9
|
+
: desc === null
|
|
10
|
+
? (desc = Object.getOwnPropertyDescriptor(target, key))
|
|
11
|
+
: desc,
|
|
12
|
+
d;
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
14
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
15
|
+
else
|
|
16
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
17
|
+
if ((d = decorators[i]))
|
|
18
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
19
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
20
|
+
};
|
|
21
|
+
var __metadata =
|
|
22
|
+
(this && this.__metadata) ||
|
|
23
|
+
function (k, v) {
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
25
|
+
return Reflect.metadata(k, v);
|
|
26
|
+
};
|
|
27
|
+
var __param =
|
|
28
|
+
(this && this.__param) ||
|
|
29
|
+
function (paramIndex, decorator) {
|
|
30
|
+
return function (target, key) {
|
|
31
|
+
decorator(target, key, paramIndex);
|
|
32
|
+
};
|
|
33
|
+
};
|
|
14
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
35
|
exports.ModuleGuard = void 0;
|
|
16
36
|
const common_1 = require("@nestjs/common");
|
|
17
37
|
let ModuleGuard = class ModuleGuard {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
38
|
+
constructor(config) {
|
|
39
|
+
this.config = config;
|
|
40
|
+
}
|
|
41
|
+
canActivate(context) {
|
|
42
|
+
const request = context.switchToHttp().getRequest();
|
|
43
|
+
const user = request.user;
|
|
44
|
+
// SuperAdmin can bypass module checks
|
|
45
|
+
const isSuperAdmin = user.roleId === 1;
|
|
46
|
+
if (isSuperAdmin) return true;
|
|
47
|
+
return user.moduleId === this.config.moduleId;
|
|
48
|
+
}
|
|
30
49
|
};
|
|
31
50
|
exports.ModuleGuard = ModuleGuard;
|
|
32
|
-
exports.ModuleGuard = ModuleGuard = __decorate(
|
|
51
|
+
exports.ModuleGuard = ModuleGuard = __decorate(
|
|
52
|
+
[
|
|
33
53
|
(0, common_1.Injectable)(),
|
|
34
|
-
__param(0, (0, common_1.Inject)(
|
|
35
|
-
__metadata("design:paramtypes", [Object])
|
|
36
|
-
],
|
|
54
|
+
__param(0, (0, common_1.Inject)("MODULE_CONFIG")),
|
|
55
|
+
__metadata("design:paramtypes", [Object]),
|
|
56
|
+
],
|
|
57
|
+
ModuleGuard
|
|
58
|
+
);
|