ecrs-auth-core 1.0.37 → 1.0.39
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.controller.d.ts +10 -0
- package/dist/auth.controller.js +0 -1
- package/dist/auth.module.js +2 -0
- package/dist/auth.service.d.ts +10 -0
- package/dist/auth.service.js +10 -0
- package/dist/entities/role.entity.d.ts +2 -1
- package/dist/entities/role.entity.js +13 -5
- package/dist/guards/module.guard.js +27 -49
- package/package.json +1 -1
|
@@ -4,6 +4,16 @@ export declare class AuthController {
|
|
|
4
4
|
private readonly authService;
|
|
5
5
|
constructor(authService: AuthService);
|
|
6
6
|
login(body: LoginDto): Promise<{
|
|
7
|
+
status: boolean;
|
|
8
|
+
message: string;
|
|
9
|
+
data: {
|
|
10
|
+
user: {
|
|
11
|
+
id: number;
|
|
12
|
+
email: string;
|
|
13
|
+
roleId: number;
|
|
14
|
+
moduleId: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
7
17
|
access_token: string;
|
|
8
18
|
}>;
|
|
9
19
|
}
|
package/dist/auth.controller.js
CHANGED
|
@@ -13,7 +13,6 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.AuthController = void 0;
|
|
16
|
-
// src/auth.controller.ts
|
|
17
16
|
const common_1 = require("@nestjs/common");
|
|
18
17
|
const auth_service_1 = require("./auth.service");
|
|
19
18
|
const login_dto_1 = require("./dtos/login.dto");
|
package/dist/auth.module.js
CHANGED
|
@@ -117,6 +117,7 @@ let AuthCoreModule = AuthCoreModule_1 = class AuthCoreModule {
|
|
|
117
117
|
feature_guard_1.FeatureGuard,
|
|
118
118
|
route_guard_1.RouteGuard,
|
|
119
119
|
permission_guard_1.PermissionGuard,
|
|
120
|
+
jwt_1.JwtService
|
|
120
121
|
],
|
|
121
122
|
controllers: [auth_controller_1.AuthController],
|
|
122
123
|
exports: [
|
|
@@ -125,6 +126,7 @@ let AuthCoreModule = AuthCoreModule_1 = class AuthCoreModule {
|
|
|
125
126
|
'MODULE_CONFIG',
|
|
126
127
|
// optional but handy:
|
|
127
128
|
jwt_1.JwtModule,
|
|
129
|
+
jwt_1.JwtService,
|
|
128
130
|
auth_service_1.AuthService,
|
|
129
131
|
jwt_strategy_1.JwtStrategy,
|
|
130
132
|
jwt_guard_1.JwtAuthGuard,
|
package/dist/auth.service.d.ts
CHANGED
|
@@ -23,6 +23,16 @@ export declare class AuthService {
|
|
|
23
23
|
constructor(jwtService: JwtService, options: AuthCoreOptions);
|
|
24
24
|
validateUser(email: string, password: string): Promise<User | null>;
|
|
25
25
|
login(user: User): Promise<{
|
|
26
|
+
status: boolean;
|
|
27
|
+
message: string;
|
|
28
|
+
data: {
|
|
29
|
+
user: {
|
|
30
|
+
id: number;
|
|
31
|
+
email: string;
|
|
32
|
+
roleId: number;
|
|
33
|
+
moduleId: number;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
26
36
|
access_token: string;
|
|
27
37
|
}>;
|
|
28
38
|
findUserById(id: number): Promise<User | null>;
|
package/dist/auth.service.js
CHANGED
|
@@ -81,6 +81,16 @@ let AuthService = class AuthService {
|
|
|
81
81
|
permissions: permissionTree,
|
|
82
82
|
};
|
|
83
83
|
return {
|
|
84
|
+
status: true,
|
|
85
|
+
message: 'Login successful',
|
|
86
|
+
data: {
|
|
87
|
+
user: {
|
|
88
|
+
id: user.id,
|
|
89
|
+
email: user.email,
|
|
90
|
+
roleId: user.roleId,
|
|
91
|
+
moduleId: user.moduleId,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
84
94
|
access_token: this.jwtService.sign(payload),
|
|
85
95
|
};
|
|
86
96
|
}
|
|
@@ -10,25 +10,33 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Role = void 0;
|
|
13
|
-
// src/entities/role.entity.ts
|
|
14
13
|
const typeorm_1 = require("typeorm");
|
|
15
14
|
let Role = class Role {
|
|
16
15
|
};
|
|
17
16
|
exports.Role = Role;
|
|
18
17
|
__decorate([
|
|
19
|
-
(0, typeorm_1.PrimaryGeneratedColumn)(),
|
|
18
|
+
(0, typeorm_1.PrimaryGeneratedColumn)('increment', { name: 'id' }),
|
|
20
19
|
__metadata("design:type", Number)
|
|
21
20
|
], Role.prototype, "id", void 0);
|
|
22
21
|
__decorate([
|
|
23
|
-
(0, typeorm_1.Column)({ name: '
|
|
22
|
+
(0, typeorm_1.Column)({ name: 'module_id', type: 'int', nullable: true }),
|
|
23
|
+
__metadata("design:type", Number)
|
|
24
|
+
], Role.prototype, "module_id", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, typeorm_1.Column)({ name: 'role_name', type: 'varchar', length: 100, unique: true }),
|
|
24
27
|
__metadata("design:type", String)
|
|
25
28
|
], Role.prototype, "roleName", void 0);
|
|
26
29
|
__decorate([
|
|
27
|
-
(0, typeorm_1.Column)({
|
|
30
|
+
(0, typeorm_1.Column)({
|
|
31
|
+
name: 'role_description',
|
|
32
|
+
type: 'varchar',
|
|
33
|
+
length: 255,
|
|
34
|
+
nullable: true,
|
|
35
|
+
}),
|
|
28
36
|
__metadata("design:type", String)
|
|
29
37
|
], Role.prototype, "roleDescription", void 0);
|
|
30
38
|
__decorate([
|
|
31
|
-
(0, typeorm_1.Column)({ name: 'is_active', default: true }),
|
|
39
|
+
(0, typeorm_1.Column)({ name: 'is_active', type: 'boolean', default: true }),
|
|
32
40
|
__metadata("design:type", Boolean)
|
|
33
41
|
], Role.prototype, "isActive", void 0);
|
|
34
42
|
exports.Role = Role = __decorate([
|
|
@@ -1,58 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __decorate =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
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;
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
19
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
20
|
-
|
|
21
|
-
var __metadata =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var __param =
|
|
28
|
-
(this && this.__param) ||
|
|
29
|
-
function (paramIndex, decorator) {
|
|
30
|
-
return function (target, key) {
|
|
31
|
-
decorator(target, key, paramIndex);
|
|
32
|
-
};
|
|
33
|
-
};
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
34
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
15
|
exports.ModuleGuard = void 0;
|
|
36
16
|
const common_1 = require("@nestjs/common");
|
|
37
17
|
let ModuleGuard = class ModuleGuard {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.config = config;
|
|
20
|
+
}
|
|
21
|
+
canActivate(context) {
|
|
22
|
+
const request = context.switchToHttp().getRequest();
|
|
23
|
+
const user = request.user;
|
|
24
|
+
// SuperAdmin can bypass module checks
|
|
25
|
+
const isSuperAdmin = user.roleId === 1;
|
|
26
|
+
if (isSuperAdmin)
|
|
27
|
+
return true;
|
|
28
|
+
return user.moduleId === this.config.moduleId;
|
|
29
|
+
}
|
|
49
30
|
};
|
|
50
31
|
exports.ModuleGuard = ModuleGuard;
|
|
51
|
-
exports.ModuleGuard = ModuleGuard = __decorate(
|
|
52
|
-
[
|
|
32
|
+
exports.ModuleGuard = ModuleGuard = __decorate([
|
|
53
33
|
(0, common_1.Injectable)(),
|
|
54
|
-
__param(0, (0, common_1.Inject)(
|
|
55
|
-
__metadata("design:paramtypes", [Object])
|
|
56
|
-
|
|
57
|
-
ModuleGuard
|
|
58
|
-
);
|
|
34
|
+
__param(0, (0, common_1.Inject)('MODULE_CONFIG')),
|
|
35
|
+
__metadata("design:paramtypes", [Object])
|
|
36
|
+
], ModuleGuard);
|