@lenne.tech/nest-server 9.2.4 → 9.2.5
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/core/modules/auth/guards/auth.guard.js.map +1 -1
- package/dist/core/modules/auth/guards/roles.guard.js +11 -1
- package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/modules/auth/guards/auth.guard.ts +1 -2
- package/src/core/modules/auth/guards/roles.guard.ts +13 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "9.2.
|
|
3
|
+
"version": "9.2.5",
|
|
4
4
|
"description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { CanActivate, ExecutionContext, Logger, mixin, Optional
|
|
1
|
+
import { CanActivate, ExecutionContext, Logger, mixin, Optional } from '@nestjs/common';
|
|
2
2
|
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
3
3
|
import { AuthModuleOptions, Type } from '@nestjs/passport';
|
|
4
4
|
import { defaultOptions } from '@nestjs/passport/dist/options';
|
|
5
5
|
import { memoize } from '@nestjs/passport/dist/utils/memoize.util';
|
|
6
|
-
import * as jwt from 'jsonwebtoken';
|
|
7
6
|
import * as passport from 'passport';
|
|
8
7
|
import { AuthGuardStrategy } from '../auth-guard-strategy.enum';
|
|
9
8
|
import { ExpiredRefreshTokenException } from '../exceptions/expired-refresh-token.exception';
|
|
@@ -3,6 +3,8 @@ import { Reflector } from '@nestjs/core';
|
|
|
3
3
|
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
4
4
|
import { RoleEnum } from '../../../common/enums/role.enum';
|
|
5
5
|
import { AuthGuardStrategy } from '../auth-guard-strategy.enum';
|
|
6
|
+
import { ExpiredTokenException } from '../exceptions/expired-token.exception';
|
|
7
|
+
import { InvalidTokenException } from '../exceptions/invalid-token.exception';
|
|
6
8
|
import { AuthGuard } from './auth.guard';
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -45,14 +47,22 @@ export class RolesGuard extends AuthGuard(AuthGuardStrategy.JWT) {
|
|
|
45
47
|
|
|
46
48
|
// Check user and user roles
|
|
47
49
|
if (!user?.hasRole?.(roles)) {
|
|
48
|
-
// Get args
|
|
49
|
-
const args: any = GqlExecutionContext.create(context).getArgs();
|
|
50
|
-
|
|
51
50
|
// Check special user roles (user is logged in or access is free for any)
|
|
52
51
|
if ((user && roles.includes(RoleEnum.S_USER)) || roles.includes(RoleEnum.S_EVERYONE)) {
|
|
53
52
|
return user;
|
|
54
53
|
}
|
|
55
54
|
|
|
55
|
+
// If user is missing throw token exception
|
|
56
|
+
if (!user) {
|
|
57
|
+
if (err) {
|
|
58
|
+
throw new InvalidTokenException();
|
|
59
|
+
}
|
|
60
|
+
if (info?.name === 'TokenExpiredError') {
|
|
61
|
+
throw new ExpiredTokenException();
|
|
62
|
+
}
|
|
63
|
+
throw new UnauthorizedException('Unauthorized');
|
|
64
|
+
}
|
|
65
|
+
|
|
56
66
|
// Requester is not authorized
|
|
57
67
|
throw new UnauthorizedException('Missing role');
|
|
58
68
|
}
|