@appxdigital/appx-core 0.1.71 → 0.1.73
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/common/guards/user-population.guard.d.ts +12 -0
- package/dist/common/guards/user-population.guard.d.ts.map +1 -0
- package/dist/common/guards/user-population.guard.js +52 -0
- package/dist/common/interfaces/user.interface.d.ts +2 -0
- package/dist/common/interfaces/user.interface.d.ts.map +1 -1
- package/dist/common/types.d.ts +1 -1
- package/dist/common/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/modules/auth/auth.controller.d.ts +12 -0
- package/dist/modules/auth/auth.controller.d.ts.map +1 -1
- package/dist/modules/auth/auth.controller.js +40 -0
- package/dist/modules/auth/auth.module.d.ts.map +1 -1
- package/dist/modules/auth/auth.module.js +17 -3
- package/dist/modules/auth/auth.service.d.ts +16 -1
- package/dist/modules/auth/auth.service.d.ts.map +1 -1
- package/dist/modules/auth/auth.service.js +79 -1
- package/dist/modules/auth/jwt-auth.guard.d.ts +7 -0
- package/dist/modules/auth/jwt-auth.guard.d.ts.map +1 -0
- package/dist/modules/auth/jwt-auth.guard.js +28 -0
- package/dist/modules/auth/jwt.strategy.d.ts +13 -0
- package/dist/modules/auth/jwt.strategy.d.ts.map +1 -0
- package/dist/modules/auth/jwt.strategy.js +44 -0
- package/dist/modules/auth/refresh-token.guard.d.ts +5 -0
- package/dist/modules/auth/refresh-token.guard.d.ts.map +1 -0
- package/dist/modules/auth/refresh-token.guard.js +17 -0
- package/dist/modules/auth/refresh-token.strategy.d.ts +17 -0
- package/dist/modules/auth/refresh-token.strategy.d.ts.map +1 -0
- package/dist/modules/auth/refresh-token.strategy.js +67 -0
- package/dist/modules/auth/session/session-serializer.d.ts +1 -1
- package/dist/modules/auth/session/session-serializer.d.ts.map +1 -1
- package/dist/modules/auth/session/session-serializer.js +4 -0
- package/dist/modules/common.module.d.ts.map +1 -1
- package/dist/modules/common.module.js +3 -2
- package/dist/modules/core/core.module.d.ts.map +1 -1
- package/dist/modules/core/core.module.js +3 -2
- package/dist/modules/core/core.service.d.ts +2 -1
- package/dist/modules/core/core.service.d.ts.map +1 -1
- package/dist/modules/core/core.service.js +6 -2
- package/dist/prisma/prisma.service.d.ts +1 -0
- package/dist/prisma/prisma.service.d.ts.map +1 -1
- package/dist/prisma/prisma.service.js +8 -5
- package/package.json +70 -66
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { JwtService } from '@nestjs/jwt';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
import { AuthService } from '../../modules/auth/auth.service';
|
|
5
|
+
export declare class UserPopulationGuard implements CanActivate {
|
|
6
|
+
private readonly jwtService;
|
|
7
|
+
private readonly authService;
|
|
8
|
+
private readonly configService;
|
|
9
|
+
constructor(jwtService: JwtService, authService: AuthService, configService: ConfigService);
|
|
10
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=user-population.guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-population.guard.d.ts","sourceRoot":"","sources":["../../../src/common/guards/user-population.guard.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,WAAW,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,qBACa,mBAAoB,YAAW,WAAW;IAE/C,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAFb,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa;IAG3C,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAyBjE"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UserPopulationGuard = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
15
|
+
const config_1 = require("@nestjs/config");
|
|
16
|
+
const auth_service_1 = require("../../modules/auth/auth.service");
|
|
17
|
+
let UserPopulationGuard = class UserPopulationGuard {
|
|
18
|
+
constructor(jwtService, authService, configService) {
|
|
19
|
+
this.jwtService = jwtService;
|
|
20
|
+
this.authService = authService;
|
|
21
|
+
this.configService = configService;
|
|
22
|
+
}
|
|
23
|
+
async canActivate(context) {
|
|
24
|
+
const request = context.switchToHttp().getRequest();
|
|
25
|
+
if (request.isAuthenticated && request.isAuthenticated()) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
// If there is no session, we try to populate user from JWT
|
|
29
|
+
const authHeader = request.headers.authorization;
|
|
30
|
+
if (authHeader && authHeader.startsWith('Bearer ')) {
|
|
31
|
+
const token = authHeader.substring(7, authHeader.length);
|
|
32
|
+
try {
|
|
33
|
+
const payload = await this.jwtService.verifyAsync(token, {
|
|
34
|
+
secret: this.configService.get('JWT_SECRET'),
|
|
35
|
+
});
|
|
36
|
+
request.user = await this.authService.validateJwtPayload(payload);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
// If Token is invalid, expired, or something else went wrong.
|
|
40
|
+
// We do nothing and the user remains unauthenticated (a GUEST).
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.UserPopulationGuard = UserPopulationGuard;
|
|
47
|
+
exports.UserPopulationGuard = UserPopulationGuard = __decorate([
|
|
48
|
+
(0, common_1.Injectable)(),
|
|
49
|
+
__metadata("design:paramtypes", [jwt_1.JwtService,
|
|
50
|
+
auth_service_1.AuthService,
|
|
51
|
+
config_1.ConfigService])
|
|
52
|
+
], UserPopulationGuard);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.interface.d.ts","sourceRoot":"","sources":["../../../src/common/interfaces/user.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,IAAI;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"user.interface.d.ts","sourceRoot":"","sources":["../../../src/common/interfaces/user.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,IAAI;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B"}
|
package/dist/common/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,iBAAiB,CAAC;AAEzB,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAEhD,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,OAAO,CAAC;QACd,UAAU,OAAO;YACb,MAAM,CAAC,EAAE,YAAY,CAAC;YAEtB,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,CAAC;YAEjD,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,CAAC;YAE3C,IAAI,CAAC,EAAE,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,iBAAiB,CAAC;AAEzB,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAEhD,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,OAAO,CAAC;QACd,UAAU,OAAO;YACb,MAAM,CAAC,EAAE,YAAY,CAAC;YAEtB,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,CAAC;YAEjD,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,CAAC;YAE3C,IAAI,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;SAC3B;QAED,UAAU,IAAK,SAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;SACzC;KACJ;CACJ;AAED,OAAO,QAAQ,iBAAiB,CAAC;IAC7B,UAAU,WAAW;QACjB,MAAM,EAAE,MAAM,CAAC;KAClB;CACJ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './tasks/session-cleanup.service';
|
|
|
8
8
|
export * from './modules/auth/auth.module';
|
|
9
9
|
export * from './modules/auth/session/session-store';
|
|
10
10
|
export * from './common/guards/rbac.guard';
|
|
11
|
+
export * from './common/guards/user-population.guard';
|
|
11
12
|
export * from './modules/common.module';
|
|
12
13
|
export * from './common/interceptors/prisma.interceptor';
|
|
13
14
|
export * from './common/config/permissionsConfigTypes';
|
|
@@ -21,4 +22,6 @@ export * from './modules/file/file-upload.controller';
|
|
|
21
22
|
export * from './modules/file/file-upload.service';
|
|
22
23
|
export * from './common/decorators/permission.decorator';
|
|
23
24
|
export * from './common/interceptors/file.interceptor';
|
|
25
|
+
export * from './modules/auth/authenticated.guard';
|
|
26
|
+
export * from './modules/auth/jwt-auth.guard';
|
|
24
27
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC;AAClD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,wCAAwC,CAAC;AACvD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,uCAAuC,CAAC;AACtD,cAAc,oCAAoC,CAAC;AACnD,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uCAAuC,CAAC;AACtD,cAAc,yBAAyB,CAAC;AACxC,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC;AAClD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,wCAAwC,CAAC;AACvD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,uCAAuC,CAAC;AACtD,cAAc,oCAAoC,CAAC;AACnD,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __exportStar(require("./tasks/session-cleanup.service"), exports);
|
|
|
24
24
|
__exportStar(require("./modules/auth/auth.module"), exports);
|
|
25
25
|
__exportStar(require("./modules/auth/session/session-store"), exports);
|
|
26
26
|
__exportStar(require("./common/guards/rbac.guard"), exports);
|
|
27
|
+
__exportStar(require("./common/guards/user-population.guard"), exports);
|
|
27
28
|
__exportStar(require("./modules/common.module"), exports);
|
|
28
29
|
__exportStar(require("./common/interceptors/prisma.interceptor"), exports);
|
|
29
30
|
__exportStar(require("./common/config/permissionsConfigTypes"), exports);
|
|
@@ -37,3 +38,5 @@ __exportStar(require("./modules/file/file-upload.controller"), exports);
|
|
|
37
38
|
__exportStar(require("./modules/file/file-upload.service"), exports);
|
|
38
39
|
__exportStar(require("./common/decorators/permission.decorator"), exports);
|
|
39
40
|
__exportStar(require("./common/interceptors/file.interceptor"), exports);
|
|
41
|
+
__exportStar(require("./modules/auth/authenticated.guard"), exports);
|
|
42
|
+
__exportStar(require("./modules/auth/jwt-auth.guard"), exports);
|
|
@@ -21,5 +21,17 @@ export declare class AuthController {
|
|
|
21
21
|
sessions: any;
|
|
22
22
|
}>;
|
|
23
23
|
closeSpecificSession(sessionId: string, req: Request, res: Response): Promise<void>;
|
|
24
|
+
loginJwt(req: Request): Promise<{
|
|
25
|
+
access_token: string;
|
|
26
|
+
refresh_token: string;
|
|
27
|
+
user: any;
|
|
28
|
+
}>;
|
|
29
|
+
refreshTokens(req: Request): Promise<{
|
|
30
|
+
access_token: string;
|
|
31
|
+
refresh_token: string;
|
|
32
|
+
}>;
|
|
33
|
+
logoutJwt(req: Request): Promise<{
|
|
34
|
+
message: string;
|
|
35
|
+
}>;
|
|
24
36
|
}
|
|
25
37
|
//# sourceMappingURL=auth.controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAG/C,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAI1C,qBACa,cAAc;IACX,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW;IAG/C,QAAQ,CAAS,WAAW,EAAE,WAAW;;;;IAMzC,KAAK,CAAQ,GAAG,EAAE,OAAO,EAAS,GAAG,EAAE,QAAQ;IAW/C,MAAM,CAAQ,GAAG,EAAE,OAAO,EAAS,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBhE,EAAE,CAAQ,GAAG,EAAE,OAAO;;;IAQtB,iBAAiB,CAAQ,GAAG,EAAE,OAAO;;;IAOrC,gBAAgB,CAAQ,GAAG,EAAE,OAAO,EAAS,GAAG,EAAE,QAAQ;IAK1D,cAAc,CAAkB,MAAM,EAAE,MAAM,EAAS,GAAG,EAAE,OAAO;;;IAUnE,oBAAoB,CACF,SAAS,EAAE,MAAM,EAC9B,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ;IAgBlB,QAAQ,CAAQ,GAAG,EAAE,OAAO;;;;;IAM5B,aAAa,CAAQ,GAAG,EAAE,OAAO;;;;IAOjC,SAAS,CAAQ,GAAG,EAAE,OAAO;;;CAQtC"}
|
|
@@ -18,6 +18,7 @@ const auth_service_1 = require("./auth.service");
|
|
|
18
18
|
const register_dto_1 = require("./dto/register.dto");
|
|
19
19
|
const local_auth_guard_1 = require("./local-auth.guard");
|
|
20
20
|
const authenticated_guard_1 = require("./authenticated.guard");
|
|
21
|
+
const refresh_token_guard_1 = require("./refresh-token.guard");
|
|
21
22
|
let AuthController = class AuthController {
|
|
22
23
|
constructor(authService) {
|
|
23
24
|
this.authService = authService;
|
|
@@ -83,6 +84,21 @@ let AuthController = class AuthController {
|
|
|
83
84
|
res.status(common_1.HttpStatus.NOT_FOUND).send({ message: 'Session not found.' });
|
|
84
85
|
}
|
|
85
86
|
}
|
|
87
|
+
async loginJwt(req) {
|
|
88
|
+
return await this.authService.loginJwt(req.user);
|
|
89
|
+
}
|
|
90
|
+
async refreshTokens(req) {
|
|
91
|
+
const userFromGuard = req.user;
|
|
92
|
+
return this.authService.refreshTokens(userFromGuard);
|
|
93
|
+
}
|
|
94
|
+
async logoutJwt(req) {
|
|
95
|
+
const userId = req.user?.id;
|
|
96
|
+
if (!userId) {
|
|
97
|
+
throw new common_1.HttpException('Unauthorized', common_1.HttpStatus.UNAUTHORIZED);
|
|
98
|
+
}
|
|
99
|
+
await this.authService.revokeRefreshTokensForUser(userId);
|
|
100
|
+
return { message: 'Logout successful' };
|
|
101
|
+
}
|
|
86
102
|
};
|
|
87
103
|
exports.AuthController = AuthController;
|
|
88
104
|
__decorate([
|
|
@@ -152,6 +168,30 @@ __decorate([
|
|
|
152
168
|
__metadata("design:paramtypes", [String, Object, Object]),
|
|
153
169
|
__metadata("design:returntype", Promise)
|
|
154
170
|
], AuthController.prototype, "closeSpecificSession", null);
|
|
171
|
+
__decorate([
|
|
172
|
+
(0, common_1.UseGuards)(local_auth_guard_1.LocalAuthGuard),
|
|
173
|
+
(0, common_1.Post)('login/jwt'),
|
|
174
|
+
__param(0, (0, common_1.Req)()),
|
|
175
|
+
__metadata("design:type", Function),
|
|
176
|
+
__metadata("design:paramtypes", [Object]),
|
|
177
|
+
__metadata("design:returntype", Promise)
|
|
178
|
+
], AuthController.prototype, "loginJwt", null);
|
|
179
|
+
__decorate([
|
|
180
|
+
(0, common_1.UseGuards)(refresh_token_guard_1.RefreshTokenGuard),
|
|
181
|
+
(0, common_1.Post)('refresh'),
|
|
182
|
+
__param(0, (0, common_1.Req)()),
|
|
183
|
+
__metadata("design:type", Function),
|
|
184
|
+
__metadata("design:paramtypes", [Object]),
|
|
185
|
+
__metadata("design:returntype", Promise)
|
|
186
|
+
], AuthController.prototype, "refreshTokens", null);
|
|
187
|
+
__decorate([
|
|
188
|
+
(0, common_1.UseGuards)(local_auth_guard_1.LocalAuthGuard),
|
|
189
|
+
(0, common_1.Post)('logout/jwt'),
|
|
190
|
+
__param(0, (0, common_1.Req)()),
|
|
191
|
+
__metadata("design:type", Function),
|
|
192
|
+
__metadata("design:paramtypes", [Object]),
|
|
193
|
+
__metadata("design:returntype", Promise)
|
|
194
|
+
], AuthController.prototype, "logoutJwt", null);
|
|
155
195
|
exports.AuthController = AuthController = __decorate([
|
|
156
196
|
(0, common_1.Controller)('auth'),
|
|
157
197
|
__metadata("design:paramtypes", [auth_service_1.AuthService])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.module.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.module.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.module.ts"],"names":[],"mappings":"AAcA,qBAea,UAAU;CACtB"}
|
|
@@ -15,14 +15,28 @@ const local_strategy_1 = require("./local.strategy");
|
|
|
15
15
|
const passport_1 = require("@nestjs/passport");
|
|
16
16
|
const session_serializer_1 = require("./session/session-serializer");
|
|
17
17
|
const config_1 = require("@nestjs/config");
|
|
18
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
19
|
+
const jwt_auth_guard_1 = require("./jwt-auth.guard");
|
|
20
|
+
const authenticated_guard_1 = require("./authenticated.guard");
|
|
21
|
+
const jwt_strategy_1 = require("./jwt.strategy");
|
|
22
|
+
const refresh_token_strategy_1 = require("./refresh-token.strategy");
|
|
18
23
|
let AuthModule = class AuthModule {
|
|
19
24
|
};
|
|
20
25
|
exports.AuthModule = AuthModule;
|
|
21
26
|
exports.AuthModule = AuthModule = __decorate([
|
|
27
|
+
(0, common_1.Global)(),
|
|
22
28
|
(0, common_1.Module)({
|
|
23
|
-
imports: [config_1.ConfigModule, user_module_1.UserModule, passport_1.PassportModule.register({ session: true })
|
|
24
|
-
|
|
29
|
+
imports: [config_1.ConfigModule, user_module_1.UserModule, passport_1.PassportModule.register({ session: true }),
|
|
30
|
+
jwt_1.JwtModule.registerAsync({
|
|
31
|
+
imports: [config_1.ConfigModule],
|
|
32
|
+
useFactory: async (config) => ({
|
|
33
|
+
secret: config.get('JWT_SECRET'),
|
|
34
|
+
signOptions: { expiresIn: config.get('JWT_EXPIRES_IN', '60m') },
|
|
35
|
+
}),
|
|
36
|
+
inject: [config_1.ConfigService],
|
|
37
|
+
}),],
|
|
38
|
+
providers: [auth_service_1.AuthService, local_strategy_1.LocalStrategy, session_serializer_1.SessionSerializer, jwt_strategy_1.JwtStrategy, jwt_auth_guard_1.JwtAuthGuard, authenticated_guard_1.AuthenticatedGuard, refresh_token_strategy_1.RefreshTokenStrategy],
|
|
25
39
|
controllers: [auth_controller_1.AuthController],
|
|
26
|
-
exports: [auth_service_1.AuthService],
|
|
40
|
+
exports: [auth_service_1.AuthService, jwt_auth_guard_1.JwtAuthGuard, authenticated_guard_1.AuthenticatedGuard, jwt_1.JwtModule],
|
|
27
41
|
})
|
|
28
42
|
], AuthModule);
|
|
@@ -3,12 +3,14 @@ import { RegisterDto } from './dto/register.dto';
|
|
|
3
3
|
import { PrismaService } from '../../prisma/prisma.service';
|
|
4
4
|
import { ConfigService } from '@nestjs/config';
|
|
5
5
|
import { Request, Response } from 'express';
|
|
6
|
+
import { JwtService } from "@nestjs/jwt";
|
|
6
7
|
export declare class AuthService {
|
|
7
8
|
private readonly userService;
|
|
8
9
|
private prisma;
|
|
10
|
+
private readonly jwtService;
|
|
9
11
|
private configService;
|
|
10
12
|
private readonly sessionCookieName;
|
|
11
|
-
constructor(userService: UserService, prisma: PrismaService, configService: ConfigService);
|
|
13
|
+
constructor(userService: UserService, prisma: PrismaService, jwtService: JwtService, configService: ConfigService);
|
|
12
14
|
register(registerDto: RegisterDto): Promise<{
|
|
13
15
|
message: string;
|
|
14
16
|
user: any;
|
|
@@ -24,5 +26,18 @@ export declare class AuthService {
|
|
|
24
26
|
closeAllUserSessions(req: Request, res: Response): Promise<void>;
|
|
25
27
|
getSessionsByUserId(userId: number): Promise<any>;
|
|
26
28
|
closeSpecificSession(sessionId: string): Promise<boolean>;
|
|
29
|
+
validateJwtPayload(payload: any): Promise<any>;
|
|
30
|
+
private generateTokens;
|
|
31
|
+
refreshTokens(userFromRefreshTokenGuard: any): Promise<{
|
|
32
|
+
access_token: string;
|
|
33
|
+
refresh_token: string;
|
|
34
|
+
}>;
|
|
35
|
+
private parseExpiry;
|
|
36
|
+
loginJwt(userFromAuthGuard: any): Promise<{
|
|
37
|
+
access_token: string;
|
|
38
|
+
refresh_token: string;
|
|
39
|
+
user: any;
|
|
40
|
+
}>;
|
|
41
|
+
revokeRefreshTokensForUser(userId: number): Promise<void>;
|
|
27
42
|
}
|
|
28
43
|
//# sourceMappingURL=auth.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.service.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,WAAW,EAAC,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAIvC,qBACa,WAAW;IAIhB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,aAAa;IANzB,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;gBAGtB,WAAW,EAAE,WAAW,EACjC,MAAM,EAAE,aAAa,EACZ,UAAU,EAAE,UAAU,EAC/B,aAAa,EAAE,aAAa;IAKlC,QAAQ,CAAC,WAAW,EAAE,WAAW;;;;IAwBjC,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAC,CAAC;IA8B1D,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBlD,YAAY,CACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,GACtB,OAAO,CAAC,GAAG,CAAC;IAuBT,cAAc,CAAC,GAAG,EAAE,OAAO;IAW3B,iBAAiB,CAAC,GAAG,EAAE,OAAO;IAW9B,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ;IA0BhD,mBAAmB,CAAC,MAAM,EAAE,MAAM;IAMlC,oBAAoB,CAAC,SAAS,EAAE,MAAM;IAOtC,kBAAkB,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;YAQtC,cAAc;IA8BtB,aAAa,CAAC,yBAAyB,EAAE,GAAG,GAAG,OAAO,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAC,CAAC;IAmB3G,OAAO,CAAC,WAAW;IAUb,QAAQ,CAAC,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAC,CAAC;IAUnG,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAMlE"}
|
|
@@ -48,10 +48,13 @@ const user_service_1 = require("../user/user.service");
|
|
|
48
48
|
const argon2 = __importStar(require("argon2"));
|
|
49
49
|
const prisma_service_1 = require("../../prisma/prisma.service");
|
|
50
50
|
const config_1 = require("@nestjs/config");
|
|
51
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
52
|
+
const cuid2_1 = require("@paralleldrive/cuid2");
|
|
51
53
|
let AuthService = class AuthService {
|
|
52
|
-
constructor(userService, prisma, configService) {
|
|
54
|
+
constructor(userService, prisma, jwtService, configService) {
|
|
53
55
|
this.userService = userService;
|
|
54
56
|
this.prisma = prisma;
|
|
57
|
+
this.jwtService = jwtService;
|
|
55
58
|
this.configService = configService;
|
|
56
59
|
this.sessionCookieName = this.configService.get('SESSION_COOKIE_NAME', 'defaultCookieName');
|
|
57
60
|
}
|
|
@@ -71,6 +74,7 @@ let AuthService = class AuthService {
|
|
|
71
74
|
};
|
|
72
75
|
}
|
|
73
76
|
catch (error) {
|
|
77
|
+
console.error(error);
|
|
74
78
|
throw new common_1.HttpException('There was an error while creating your account. Please try again later.', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
75
79
|
}
|
|
76
80
|
}
|
|
@@ -187,11 +191,85 @@ let AuthService = class AuthService {
|
|
|
187
191
|
}).catch(() => null);
|
|
188
192
|
return !!deleted;
|
|
189
193
|
}
|
|
194
|
+
async validateJwtPayload(payload) {
|
|
195
|
+
const user = await this.userService.findByField("id", payload.sub);
|
|
196
|
+
if (!user) {
|
|
197
|
+
throw new common_1.UnauthorizedException('Invalid token');
|
|
198
|
+
}
|
|
199
|
+
return user;
|
|
200
|
+
}
|
|
201
|
+
async generateTokens(user) {
|
|
202
|
+
const accessTokenPayload = { sub: user.id, role: user.role };
|
|
203
|
+
const refreshTokenPayload = {
|
|
204
|
+
sub: user.id,
|
|
205
|
+
jti: (0, cuid2_1.createId)(),
|
|
206
|
+
};
|
|
207
|
+
const accessToken = this.jwtService.sign(accessTokenPayload, {
|
|
208
|
+
secret: this.configService.get('JWT_SECRET'),
|
|
209
|
+
expiresIn: this.configService.get('JWT_EXPIRES_IN', '15m'),
|
|
210
|
+
});
|
|
211
|
+
const refreshTokenString = this.jwtService.sign(refreshTokenPayload, {
|
|
212
|
+
secret: this.configService.get('JWT_REFRESH_SECRET'),
|
|
213
|
+
expiresIn: this.configService.get('JWT_REFRESH_EXPIRES_IN', '7d'),
|
|
214
|
+
});
|
|
215
|
+
const refreshExpiresInMs = this.parseExpiry(this.configService.get('JWT_REFRESH_EXPIRES_IN', '7d'));
|
|
216
|
+
const expiresAt = new Date(Date.now() + refreshExpiresInMs);
|
|
217
|
+
await this.prisma.userRefreshToken.create({
|
|
218
|
+
data: {
|
|
219
|
+
token: refreshTokenString,
|
|
220
|
+
userId: user.id,
|
|
221
|
+
expiresAt: expiresAt,
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
return { access_token: accessToken, refresh_token: refreshTokenString };
|
|
225
|
+
}
|
|
226
|
+
async refreshTokens(userFromRefreshTokenGuard) {
|
|
227
|
+
const userId = userFromRefreshTokenGuard.id;
|
|
228
|
+
const currentTokenId = userFromRefreshTokenGuard.refreshTokenId;
|
|
229
|
+
const providedTokenString = userFromRefreshTokenGuard.currentRefreshToken;
|
|
230
|
+
// Invalidate the used refresh token
|
|
231
|
+
await this.prisma.userRefreshToken.update({
|
|
232
|
+
where: { id: currentTokenId },
|
|
233
|
+
data: { revokedAt: new Date() },
|
|
234
|
+
});
|
|
235
|
+
const user = await this.userService.findByField("id", userId);
|
|
236
|
+
if (!user) {
|
|
237
|
+
throw new common_1.ForbiddenException('Access Denied');
|
|
238
|
+
}
|
|
239
|
+
return this.generateTokens(user);
|
|
240
|
+
}
|
|
241
|
+
parseExpiry(expiryString) {
|
|
242
|
+
const unit = expiryString.slice(-1);
|
|
243
|
+
const value = parseInt(expiryString.slice(0, -1), 10);
|
|
244
|
+
if (unit === 'd')
|
|
245
|
+
return value * 24 * 60 * 60 * 1000;
|
|
246
|
+
if (unit === 'h')
|
|
247
|
+
return value * 60 * 60 * 1000;
|
|
248
|
+
if (unit === 'm')
|
|
249
|
+
return value * 60 * 1000;
|
|
250
|
+
return value * 1000;
|
|
251
|
+
}
|
|
252
|
+
async loginJwt(userFromAuthGuard) {
|
|
253
|
+
const user = await this.userService.findByField("id", userFromAuthGuard.id);
|
|
254
|
+
if (!user) {
|
|
255
|
+
throw new common_1.UnauthorizedException('User not found');
|
|
256
|
+
}
|
|
257
|
+
const { access_token, refresh_token } = await this.generateTokens(user);
|
|
258
|
+
const { password, ...userResult } = user;
|
|
259
|
+
return { access_token: access_token, refresh_token: refresh_token, user: userResult };
|
|
260
|
+
}
|
|
261
|
+
async revokeRefreshTokensForUser(userId) {
|
|
262
|
+
await this.prisma.userRefreshToken.updateMany({
|
|
263
|
+
where: { userId: userId, revokedAt: null },
|
|
264
|
+
data: { revokedAt: new Date() },
|
|
265
|
+
});
|
|
266
|
+
}
|
|
190
267
|
};
|
|
191
268
|
exports.AuthService = AuthService;
|
|
192
269
|
exports.AuthService = AuthService = __decorate([
|
|
193
270
|
(0, common_1.Injectable)(),
|
|
194
271
|
__metadata("design:paramtypes", [user_service_1.UserService,
|
|
195
272
|
prisma_service_1.PrismaService,
|
|
273
|
+
jwt_1.JwtService,
|
|
196
274
|
config_1.ConfigService])
|
|
197
275
|
], AuthService);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ExecutionContext } from '@nestjs/common';
|
|
2
|
+
declare const JwtAuthGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
|
|
3
|
+
export declare class JwtAuthGuard extends JwtAuthGuard_base {
|
|
4
|
+
getRequest(context: ExecutionContext): any;
|
|
5
|
+
}
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=jwt-auth.guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-auth.guard.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/jwt-auth.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;;AAK5D,qBACa,YAAa,SAAQ,iBAAgB;IAC9C,UAAU,CAAC,OAAO,EAAE,gBAAgB;CAQvC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.JwtAuthGuard = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const passport_1 = require("@nestjs/passport");
|
|
12
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
13
|
+
const context_transformer_util_1 = require("../../common/utils/context-transformer.util");
|
|
14
|
+
let JwtAuthGuard = class JwtAuthGuard extends (0, passport_1.AuthGuard)('jwt') {
|
|
15
|
+
getRequest(context) {
|
|
16
|
+
if (context.getType() === 'http') {
|
|
17
|
+
return (0, context_transformer_util_1.transformContext)(context).req;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const gqlCtx = graphql_1.GqlExecutionContext.create(context);
|
|
21
|
+
return gqlCtx.getContext().req;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.JwtAuthGuard = JwtAuthGuard;
|
|
26
|
+
exports.JwtAuthGuard = JwtAuthGuard = __decorate([
|
|
27
|
+
(0, common_1.Injectable)()
|
|
28
|
+
], JwtAuthGuard);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Strategy } from 'passport-jwt';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { AuthService } from './auth.service';
|
|
4
|
+
declare const JwtStrategy_base: new (...args: [opt: import("passport-jwt").StrategyOptionsWithRequest] | [opt: import("passport-jwt").StrategyOptionsWithoutRequest]) => Strategy & {
|
|
5
|
+
validate(...args: any[]): unknown;
|
|
6
|
+
};
|
|
7
|
+
export declare class JwtStrategy extends JwtStrategy_base {
|
|
8
|
+
private readonly authService;
|
|
9
|
+
constructor(authService: AuthService, configService: ConfigService);
|
|
10
|
+
validate(payload: any): Promise<any>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=jwt.strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.strategy.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/jwt.strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,QAAQ,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;;;;AAE7C,qBACa,WAAY,SAAQ,gBAAiC;IAE1D,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW,EACzC,aAAa,EAAE,aAAa;IAc1B,QAAQ,CAAC,OAAO,EAAE,GAAG;CAO9B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.JwtStrategy = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const passport_1 = require("@nestjs/passport");
|
|
15
|
+
const passport_jwt_1 = require("passport-jwt");
|
|
16
|
+
const config_1 = require("@nestjs/config");
|
|
17
|
+
const auth_service_1 = require("./auth.service");
|
|
18
|
+
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy, 'jwt') {
|
|
19
|
+
constructor(authService, configService) {
|
|
20
|
+
const secret = configService.get('JWT_SECRET');
|
|
21
|
+
if (!secret) {
|
|
22
|
+
throw new Error('Missing JWT_SECRET configuration');
|
|
23
|
+
}
|
|
24
|
+
super({
|
|
25
|
+
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
26
|
+
ignoreExpiration: false,
|
|
27
|
+
secretOrKey: secret,
|
|
28
|
+
});
|
|
29
|
+
this.authService = authService;
|
|
30
|
+
}
|
|
31
|
+
async validate(payload) {
|
|
32
|
+
const user = await this.authService.validateJwtPayload(payload);
|
|
33
|
+
if (!user) {
|
|
34
|
+
throw new common_1.UnauthorizedException();
|
|
35
|
+
}
|
|
36
|
+
return user;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.JwtStrategy = JwtStrategy;
|
|
40
|
+
exports.JwtStrategy = JwtStrategy = __decorate([
|
|
41
|
+
(0, common_1.Injectable)(),
|
|
42
|
+
__metadata("design:paramtypes", [auth_service_1.AuthService,
|
|
43
|
+
config_1.ConfigService])
|
|
44
|
+
], JwtStrategy);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh-token.guard.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/refresh-token.guard.ts"],"names":[],"mappings":";AAGA,qBACa,iBAAkB,SAAQ,sBAAwB;CAAG"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.RefreshTokenGuard = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const passport_1 = require("@nestjs/passport");
|
|
12
|
+
let RefreshTokenGuard = class RefreshTokenGuard extends (0, passport_1.AuthGuard)('jwt-refresh') {
|
|
13
|
+
};
|
|
14
|
+
exports.RefreshTokenGuard = RefreshTokenGuard;
|
|
15
|
+
exports.RefreshTokenGuard = RefreshTokenGuard = __decorate([
|
|
16
|
+
(0, common_1.Injectable)()
|
|
17
|
+
], RefreshTokenGuard);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Strategy } from 'passport-jwt';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { Request } from 'express';
|
|
4
|
+
import { PrismaService } from '../../prisma/prisma.service';
|
|
5
|
+
import { UserService } from '../user/user.service';
|
|
6
|
+
declare const RefreshTokenStrategy_base: new (...args: [opt: import("passport-jwt").StrategyOptionsWithRequest] | [opt: import("passport-jwt").StrategyOptionsWithoutRequest]) => Strategy & {
|
|
7
|
+
validate(...args: any[]): unknown;
|
|
8
|
+
};
|
|
9
|
+
export declare class RefreshTokenStrategy extends RefreshTokenStrategy_base {
|
|
10
|
+
private readonly configService;
|
|
11
|
+
private readonly prisma;
|
|
12
|
+
private readonly userService;
|
|
13
|
+
constructor(configService: ConfigService, prisma: PrismaService, userService: UserService);
|
|
14
|
+
validate(req: Request, payload: any): Promise<any>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=refresh-token.strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh-token.strategy.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/refresh-token.strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,QAAQ,EAAa,MAAM,cAAc,CAAC;AAClD,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAChC,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,WAAW,EAAC,MAAM,sBAAsB,CAAC;;;;AAEjD,qBACa,oBAAqB,SAAQ,yBAAyC;IAE3E,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAFX,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,WAAW;IAcvC,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG;CA6B5C"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RefreshTokenStrategy = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const passport_1 = require("@nestjs/passport");
|
|
15
|
+
const passport_jwt_1 = require("passport-jwt");
|
|
16
|
+
const config_1 = require("@nestjs/config");
|
|
17
|
+
const prisma_service_1 = require("../../prisma/prisma.service");
|
|
18
|
+
const user_service_1 = require("../user/user.service");
|
|
19
|
+
let RefreshTokenStrategy = class RefreshTokenStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy, 'jwt-refresh') {
|
|
20
|
+
constructor(configService, prisma, userService) {
|
|
21
|
+
const refreshSecret = configService.get('JWT_REFRESH_SECRET');
|
|
22
|
+
if (!refreshSecret) {
|
|
23
|
+
throw new Error('JWT_REFRESH_SECRET is not defined in environment variables!');
|
|
24
|
+
}
|
|
25
|
+
super({
|
|
26
|
+
jwtFromRequest: passport_jwt_1.ExtractJwt.fromBodyField('refreshToken'),
|
|
27
|
+
secretOrKey: refreshSecret,
|
|
28
|
+
passReqToCallback: true,
|
|
29
|
+
});
|
|
30
|
+
this.configService = configService;
|
|
31
|
+
this.prisma = prisma;
|
|
32
|
+
this.userService = userService;
|
|
33
|
+
}
|
|
34
|
+
async validate(req, payload) {
|
|
35
|
+
const refreshToken = req.body.refreshToken;
|
|
36
|
+
if (!refreshToken)
|
|
37
|
+
throw new common_1.UnauthorizedException('Refresh token not found');
|
|
38
|
+
const user = await this.userService.findByField("id", payload.sub);
|
|
39
|
+
if (!user) {
|
|
40
|
+
throw new common_1.UnauthorizedException('User not found');
|
|
41
|
+
}
|
|
42
|
+
const tokenRecord = await this.prisma.userRefreshToken.findUnique({
|
|
43
|
+
where: { token: refreshToken },
|
|
44
|
+
});
|
|
45
|
+
if (!tokenRecord) {
|
|
46
|
+
throw new common_1.UnauthorizedException('Refresh token not found in store');
|
|
47
|
+
}
|
|
48
|
+
if (tokenRecord.revokedAt) {
|
|
49
|
+
await this.prisma.userRefreshToken.updateMany({
|
|
50
|
+
where: { userId: user.id, revokedAt: null },
|
|
51
|
+
data: { revokedAt: new Date() },
|
|
52
|
+
});
|
|
53
|
+
throw new common_1.UnauthorizedException('Refresh token revoked');
|
|
54
|
+
}
|
|
55
|
+
if (new Date() > tokenRecord.expiresAt) {
|
|
56
|
+
throw new common_1.UnauthorizedException('Refresh token expired');
|
|
57
|
+
}
|
|
58
|
+
return { ...user, refreshTokenId: tokenRecord.id, currentRefreshToken: refreshToken };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.RefreshTokenStrategy = RefreshTokenStrategy;
|
|
62
|
+
exports.RefreshTokenStrategy = RefreshTokenStrategy = __decorate([
|
|
63
|
+
(0, common_1.Injectable)(),
|
|
64
|
+
__metadata("design:paramtypes", [config_1.ConfigService,
|
|
65
|
+
prisma_service_1.PrismaService,
|
|
66
|
+
user_service_1.UserService])
|
|
67
|
+
], RefreshTokenStrategy);
|
|
@@ -4,6 +4,6 @@ export declare class SessionSerializer extends PassportSerializer {
|
|
|
4
4
|
private prisma;
|
|
5
5
|
constructor(prisma: PrismaService);
|
|
6
6
|
serializeUser(user: any, done: Function): void;
|
|
7
|
-
deserializeUser(userId: string, done: Function): Promise<
|
|
7
|
+
deserializeUser(userId: string, done: Function): Promise<any>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=session-serializer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-serializer.d.ts","sourceRoot":"","sources":["../../../../src/modules/auth/session/session-serializer.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAC,aAAa,EAAC,MAAM,gCAAgC,CAAC;AAE7D,qBACa,iBAAkB,SAAQ,kBAAkB;IACzC,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAIzC,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ;IAIjC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ;
|
|
1
|
+
{"version":3,"file":"session-serializer.d.ts","sourceRoot":"","sources":["../../../../src/modules/auth/session/session-serializer.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAC,aAAa,EAAC,MAAM,gCAAgC,CAAC;AAE7D,qBACa,iBAAkB,SAAQ,kBAAkB;IACzC,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAIzC,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ;IAIjC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ;CAqBvD"}
|
|
@@ -22,6 +22,9 @@ let SessionSerializer = class SessionSerializer extends passport_1.PassportSeria
|
|
|
22
22
|
done(null, user.id);
|
|
23
23
|
}
|
|
24
24
|
async deserializeUser(userId, done) {
|
|
25
|
+
if (!userId) {
|
|
26
|
+
return done(new Error('No userId provided'), null);
|
|
27
|
+
}
|
|
25
28
|
try {
|
|
26
29
|
const user = await this.prisma.user.findUniqueOrThrow({
|
|
27
30
|
where: { id: Number(userId) },
|
|
@@ -36,6 +39,7 @@ let SessionSerializer = class SessionSerializer extends passport_1.PassportSeria
|
|
|
36
39
|
done(null, user);
|
|
37
40
|
}
|
|
38
41
|
catch (error) {
|
|
42
|
+
console.debug('Error deserializing user:', error);
|
|
39
43
|
done(new Error('User not found'), null);
|
|
40
44
|
}
|
|
41
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.module.d.ts","sourceRoot":"","sources":["../../src/modules/common.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.module.d.ts","sourceRoot":"","sources":["../../src/modules/common.module.ts"],"names":[],"mappings":"AAIA,qBAIa,YAAY;CAAG"}
|
|
@@ -9,12 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.CommonModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const rbac_guard_1 = require("../common/guards/rbac.guard");
|
|
12
|
+
const user_population_guard_1 = require("../common/guards/user-population.guard");
|
|
12
13
|
let CommonModule = class CommonModule {
|
|
13
14
|
};
|
|
14
15
|
exports.CommonModule = CommonModule;
|
|
15
16
|
exports.CommonModule = CommonModule = __decorate([
|
|
16
17
|
(0, common_1.Module)({
|
|
17
|
-
providers: [rbac_guard_1.RbacGuard],
|
|
18
|
-
exports: [rbac_guard_1.RbacGuard],
|
|
18
|
+
providers: [rbac_guard_1.RbacGuard, user_population_guard_1.UserPopulationGuard],
|
|
19
|
+
exports: [rbac_guard_1.RbacGuard, user_population_guard_1.UserPopulationGuard],
|
|
19
20
|
})
|
|
20
21
|
], CommonModule);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.module.d.ts","sourceRoot":"","sources":["../../../src/modules/core/core.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.module.d.ts","sourceRoot":"","sources":["../../../src/modules/core/core.module.ts"],"names":[],"mappings":"AAUA,qBAKa,UAAU;CACtB"}
|
|
@@ -10,13 +10,14 @@ exports.CoreModule = void 0;
|
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const rbac_guard_1 = require("../../common/guards/rbac.guard");
|
|
12
12
|
const permissions_config_provider_1 = require("../../common/config/permissions.config.provider");
|
|
13
|
+
const user_population_guard_1 = require("../../common/guards/user-population.guard");
|
|
13
14
|
let CoreModule = class CoreModule {
|
|
14
15
|
};
|
|
15
16
|
exports.CoreModule = CoreModule;
|
|
16
17
|
exports.CoreModule = CoreModule = __decorate([
|
|
17
18
|
(0, common_1.Global)(),
|
|
18
19
|
(0, common_1.Module)({
|
|
19
|
-
providers: [permissions_config_provider_1.PermissionsConfigProvider, rbac_guard_1.RbacGuard],
|
|
20
|
-
exports: [permissions_config_provider_1.PermissionsConfigProvider, rbac_guard_1.RbacGuard],
|
|
20
|
+
providers: [permissions_config_provider_1.PermissionsConfigProvider, rbac_guard_1.RbacGuard, user_population_guard_1.UserPopulationGuard],
|
|
21
|
+
exports: [permissions_config_provider_1.PermissionsConfigProvider, rbac_guard_1.RbacGuard, user_population_guard_1.UserPopulationGuard],
|
|
21
22
|
})
|
|
22
23
|
], CoreModule);
|
|
@@ -11,9 +11,10 @@ export declare class CoreService<T> {
|
|
|
11
11
|
/**
|
|
12
12
|
* Find a single record by unique identifier.
|
|
13
13
|
* @param where - Unique identifier for the record (e.g., { id: 1 })
|
|
14
|
+
* @param options - Additional query options (e.g., include, select)
|
|
14
15
|
* @returns A promise of the record
|
|
15
16
|
*/
|
|
16
|
-
findOne(where: any): Promise<T | null>;
|
|
17
|
+
findOne(where: any, options?: any): Promise<T | null>;
|
|
17
18
|
/**
|
|
18
19
|
* Find a single record by unique identifier.
|
|
19
20
|
* @param id - Unique identifier for the record (e.g., 1, 'abc123').
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.service.d.ts","sourceRoot":"","sources":["../../../src/modules/core/core.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAGjD,qBACa,WAAW,CAAC,CAAC;IAElB,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,YAAY,CAAC,MAAM,YAAY,CAAC;gBAA/C,aAAa,EAAE,YAAY,CAAC,MAAM,YAAY,CAAC;IAItE;;;;OAIG;IACG,OAAO,CAAC,MAAM,GAAE,GAAQ,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAQ7C
|
|
1
|
+
{"version":3,"file":"core.service.d.ts","sourceRoot":"","sources":["../../../src/modules/core/core.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAGjD,qBACa,WAAW,CAAC,CAAC;IAElB,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,YAAY,CAAC,MAAM,YAAY,CAAC;gBAA/C,aAAa,EAAE,YAAY,CAAC,MAAM,YAAY,CAAC;IAItE;;;;OAIG;IACG,OAAO,CAAC,MAAM,GAAE,GAAQ,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAQ7C;;;;;OAKG;IACG,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,GAAE,GAAQ,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAY/D;;;;OAIG;IACG,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAU7C;;;;OAIG;IACG,MAAM,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAQnC;;;;;OAKG;IACG,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAWnD;;;;OAIG;IACG,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAaxC,OAAO,CAAC,yBAAyB;CAUpC"}
|
|
@@ -32,10 +32,14 @@ let CoreService = class CoreService {
|
|
|
32
32
|
/**
|
|
33
33
|
* Find a single record by unique identifier.
|
|
34
34
|
* @param where - Unique identifier for the record (e.g., { id: 1 })
|
|
35
|
+
* @param options - Additional query options (e.g., include, select)
|
|
35
36
|
* @returns A promise of the record
|
|
36
37
|
*/
|
|
37
|
-
async findOne(where) {
|
|
38
|
-
const record = this.modelDelegate.findUnique({
|
|
38
|
+
async findOne(where, options = {}) {
|
|
39
|
+
const record = this.modelDelegate.findUnique({
|
|
40
|
+
where,
|
|
41
|
+
...options
|
|
42
|
+
});
|
|
39
43
|
if (!record) {
|
|
40
44
|
throw new common_1.NotFoundException(`Record with the given criteria not found`);
|
|
41
45
|
}
|
|
@@ -19,6 +19,7 @@ export declare class PrismaService {
|
|
|
19
19
|
get model(): RuntimeClient;
|
|
20
20
|
get user(): any;
|
|
21
21
|
get session(): any;
|
|
22
|
+
get userRefreshToken(): any;
|
|
22
23
|
/**
|
|
23
24
|
* Parses the Prisma schema to extract model information and field configurations
|
|
24
25
|
* including custom annotations (e.g., @Role(CLIENT)) and enums.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.service.d.ts","sourceRoot":"","sources":["../../src/prisma/prisma.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,YAAY,EAAC,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAC,qBAAqB,EAAC,MAAM,yCAAyC,CAAC;AAI9E,OAAO,KAAK,EAAC,YAAY,IAAI,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAElE,KAAK,QAAQ,GAAG,MAAM,aAAa,CAAC;AAEpC,qBACa,aAAa;IAOY,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IANpE,OAAO,CAAC,YAAY,CAA2B;IAC/C,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,CAAC,UAAU,CAAc;gBAG5B,YAAY,EAAE,YAAY,EACqB,iBAAiB,EAAE,qBAAqB;IAO3F,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,iBAAiB,KAAK,OAAO,CAAC,CAAC,CAAC;IAIpE,WAAW;IA4CX;;;;OAIG;IACH,gBAAgB,CAAC,CAAC,SAAS,QAAQ,EAAE,KAAK,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IAYhE,IAAI,KAAK,IAAI,aAAa,CAUzB;IAED,IAAI,IAAI,QAEP;IAED,IAAI,OAAO,QAEV;IAED;;;OAGG;IACH,WAAW;IASX;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAU9B;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;IA4B/B;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAsD9B,OAAO,CAAC,YAAY;
|
|
1
|
+
{"version":3,"file":"prisma.service.d.ts","sourceRoot":"","sources":["../../src/prisma/prisma.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,YAAY,EAAC,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAC,qBAAqB,EAAC,MAAM,yCAAyC,CAAC;AAI9E,OAAO,KAAK,EAAC,YAAY,IAAI,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAElE,KAAK,QAAQ,GAAG,MAAM,aAAa,CAAC;AAEpC,qBACa,aAAa;IAOY,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IANpE,OAAO,CAAC,YAAY,CAA2B;IAC/C,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,CAAC,UAAU,CAAc;gBAG5B,YAAY,EAAE,YAAY,EACqB,iBAAiB,EAAE,qBAAqB;IAO3F,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,iBAAiB,KAAK,OAAO,CAAC,CAAC,CAAC;IAIpE,WAAW;IA4CX;;;;OAIG;IACH,gBAAgB,CAAC,CAAC,SAAS,QAAQ,EAAE,KAAK,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IAYhE,IAAI,KAAK,IAAI,aAAa,CAUzB;IAED,IAAI,IAAI,QAEP;IAED,IAAI,OAAO,QAEV;IAED,IAAI,gBAAgB,QAEnB;IAED;;;OAGG;IACH,WAAW;IASX;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAU9B;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;IA4B/B;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAsD9B,OAAO,CAAC,YAAY;IAMpB;;;;;;;;OAQG;IACH,OAAO,CAAC,kBAAkB;IAiC1B,IAAI,2BAA2B,QAM9B;IAED;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,oBAAoB;IAqG5B,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;;;;;;;IAoCzD;;;;;;;OAOG;IACH,OAAO,CAAC,eAAe;IAgBvB;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAwB3B;;;;;;;OAOG;IACH,OAAO,CAAC,eAAe;IAQvB;;;;;;;;;OASG;IACH,OAAO,CAAC,iBAAiB;IAkDzB;;;;;;;;OAQG;IACH,OAAO,CAAC,mBAAmB;CAgB9B"}
|
|
@@ -137,6 +137,9 @@ let PrismaService = class PrismaService {
|
|
|
137
137
|
get session() {
|
|
138
138
|
return this.prismaClient.session;
|
|
139
139
|
}
|
|
140
|
+
get userRefreshToken() {
|
|
141
|
+
return this.prismaClient.userRefreshToken;
|
|
142
|
+
}
|
|
140
143
|
/**
|
|
141
144
|
* Parses the Prisma schema to extract model information and field configurations
|
|
142
145
|
* including custom annotations (e.g., @Role(CLIENT)) and enums.
|
|
@@ -174,7 +177,7 @@ let PrismaService = class PrismaService {
|
|
|
174
177
|
while ((match = modelRegex.exec(schema)) !== null) {
|
|
175
178
|
const modelName = match[1];
|
|
176
179
|
const modelBody = match[2];
|
|
177
|
-
const { allFields, fieldConfig, fieldTypes, scalarFields, relationFields, } = this.extractFieldsFromModel(modelBody);
|
|
180
|
+
const { allFields, fieldConfig, fieldTypes, scalarFields, relationFields, } = this.extractFieldsFromModel(modelBody, enums);
|
|
178
181
|
models[modelName.toLowerCase()] = {
|
|
179
182
|
fieldConfig,
|
|
180
183
|
allFields,
|
|
@@ -190,7 +193,7 @@ let PrismaService = class PrismaService {
|
|
|
190
193
|
* @param modelBody - The body of the model in the schema.
|
|
191
194
|
* @returns A parsed object with fields and their custom annotations.
|
|
192
195
|
*/
|
|
193
|
-
extractFieldsFromModel(modelBody) {
|
|
196
|
+
extractFieldsFromModel(modelBody, enums) {
|
|
194
197
|
const allFields = [];
|
|
195
198
|
const fieldConfig = {};
|
|
196
199
|
const fieldTypes = {};
|
|
@@ -220,7 +223,7 @@ let PrismaService = class PrismaService {
|
|
|
220
223
|
allFields.push(fieldName);
|
|
221
224
|
fieldTypes[fieldName] = fieldType;
|
|
222
225
|
let baseType = fieldType.replace('?', '').replace('[]', '');
|
|
223
|
-
if (this.isScalarType(baseType)) {
|
|
226
|
+
if (this.isScalarType(baseType, enums)) {
|
|
224
227
|
scalarFields.push(fieldName);
|
|
225
228
|
}
|
|
226
229
|
else {
|
|
@@ -236,9 +239,9 @@ let PrismaService = class PrismaService {
|
|
|
236
239
|
};
|
|
237
240
|
}
|
|
238
241
|
// Helper method to identify scalar types
|
|
239
|
-
isScalarType(fieldType) {
|
|
242
|
+
isScalarType(fieldType, enums) {
|
|
240
243
|
const scalarTypes = ['Int', 'String', 'Boolean', 'DateTime', 'Float', 'BigInt', 'Decimal', 'Json', 'Bytes', 'Unsupported'];
|
|
241
|
-
return scalarTypes.includes(fieldType);
|
|
244
|
+
return scalarTypes.includes(fieldType) || enums.includes(fieldType);
|
|
242
245
|
}
|
|
243
246
|
/**
|
|
244
247
|
* Applies field omission logic based on the user's role.
|
package/package.json
CHANGED
|
@@ -1,66 +1,70 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@appxdigital/appx-core",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Appx Core is a library that provides a set of tools to help you build your application faster.",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"npm:publish": "rimraf dist && npm run build && npm publish --access=public",
|
|
10
|
-
"db-pull": "npx prisma db pull && prisma-case-format --table-case pascal --field-case camel --enum-case pascal --file prisma/schema.prisma"
|
|
11
|
-
},
|
|
12
|
-
"keywords": [],
|
|
13
|
-
"author": "",
|
|
14
|
-
"license": "ISC",
|
|
15
|
-
"dependencies": {
|
|
16
|
-
"@aws-sdk/client-s3": "^3.
|
|
17
|
-
"@aws-sdk/
|
|
18
|
-
"@
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"@
|
|
22
|
-
"@
|
|
23
|
-
"@types/
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"@
|
|
42
|
-
"@types/
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"@nestjs/
|
|
51
|
-
"@nestjs/
|
|
52
|
-
"@nestjs/
|
|
53
|
-
"@nestjs/
|
|
54
|
-
"@
|
|
55
|
-
"nestjs
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
},
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@appxdigital/appx-core",
|
|
3
|
+
"version": "0.1.73",
|
|
4
|
+
"description": "Appx Core is a library that provides a set of tools to help you build your application faster.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"npm:publish": "rimraf dist && npm run build && npm publish --access=public",
|
|
10
|
+
"db-pull": "npx prisma db pull && prisma-case-format --table-case pascal --field-case camel --enum-case pascal --file prisma/schema.prisma"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@aws-sdk/client-s3": "^3.850.0",
|
|
17
|
+
"@aws-sdk/s3-request-presigner": "^3.850.0",
|
|
18
|
+
"@aws-sdk/types": "^3.686.0",
|
|
19
|
+
"@google-cloud/storage": "^7.14.0",
|
|
20
|
+
"@nestjs/jwt": "^11.0.0",
|
|
21
|
+
"@paljs/plugins": "^8.1.0",
|
|
22
|
+
"@paralleldrive/cuid2": "^2.2.2",
|
|
23
|
+
"@types/bcrypt": "^5.0.2",
|
|
24
|
+
"@types/express": "^5.0.0",
|
|
25
|
+
"@types/express-session": "^1.18.0",
|
|
26
|
+
"argon2": "^0.41.1",
|
|
27
|
+
"class-transformer": "^0.5.1",
|
|
28
|
+
"class-validator": "^0.14.1",
|
|
29
|
+
"express": "^4.21.1",
|
|
30
|
+
"express-session": "^1.18.1",
|
|
31
|
+
"graphql-type-json": "^0.3.2",
|
|
32
|
+
"inquirer": "^12.0.1",
|
|
33
|
+
"multer": "^1.4.5-lts.1",
|
|
34
|
+
"passport": "^0.7.0",
|
|
35
|
+
"passport-jwt": "^4.0.1",
|
|
36
|
+
"passport-local": "^1.0.0",
|
|
37
|
+
"prisma-case-format": "^2.2.1",
|
|
38
|
+
"prisma-nestjs-graphql": "21.1.1"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@prisma/client": "^6.5.0",
|
|
42
|
+
"@types/express-formidable": "^1.2.3",
|
|
43
|
+
"@types/inquirer": "^9.0.7",
|
|
44
|
+
"@types/multer": "^1.4.12",
|
|
45
|
+
"@types/passport-jwt": "^4.0.1",
|
|
46
|
+
"@types/passport-local": "^1.0.38",
|
|
47
|
+
"typescript": "^5.1.3"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@nestjs/apollo": "^13.0.0",
|
|
51
|
+
"@nestjs/common": "^11.0.0",
|
|
52
|
+
"@nestjs/config": "^4.0.0",
|
|
53
|
+
"@nestjs/core": "^11.0.0",
|
|
54
|
+
"@nestjs/graphql": "^13.1.0",
|
|
55
|
+
"@nestjs/passport": "^11.0.0",
|
|
56
|
+
"@nestjs/platform-express": "^11.0.0",
|
|
57
|
+
"@nestjs/schedule": "^6.0.0",
|
|
58
|
+
"@prisma/client": "^6.5.0",
|
|
59
|
+
"nestjs-request-context": "^4.0.0",
|
|
60
|
+
"reflect-metadata": "^0.2.0",
|
|
61
|
+
"rxjs": "^7.8.1"
|
|
62
|
+
},
|
|
63
|
+
"overrides": {
|
|
64
|
+
"rimraf": "^4.0.0",
|
|
65
|
+
"glob": "^9.0.0"
|
|
66
|
+
},
|
|
67
|
+
"files": [
|
|
68
|
+
"dist"
|
|
69
|
+
]
|
|
70
|
+
}
|