Skip to content

Commit 3cce0b0

Browse files
author
Shady Khalifa
committed
Publish v2.0.4
1 parent 62b2799 commit 3cce0b0

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

lib/decorators/user-roles.decorators.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
*
44
* You can pass an optional property key to the decorator to get it from the user object
55
* e.g `@UserRoles('permissions')` will return the `req.user.permissions` instead.
6+
* In case that the request is missing User object the function will return null
67
*/
78
export declare const UserRoles: (...dataOrPipes: (string | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;

lib/decorators/user-roles.decorators.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function userFactory(ctx) {
1717
// do something that is only important in the context of Websockets requests
1818
throw new Error('Websockets context is not implemented yet');
1919
}
20-
else if (ctx.getType() === 'graphql') {
20+
else if (contextType === 'graphql') {
2121
// inline require here, since we don't want to require the graphql module in the pacakge.
2222
const { GqlExecutionContext } = require('@nestjs/graphql');
2323
// do something that is only important in the context of GraphQL requests
@@ -31,8 +31,11 @@ function userFactory(ctx) {
3131
*
3232
* You can pass an optional property key to the decorator to get it from the user object
3333
* e.g `@UserRoles('permissions')` will return the `req.user.permissions` instead.
34+
* In case that the request is missing User object the function will return null
3435
*/
35-
exports.UserRoles = (0, common_1.createParamDecorator)((data, ctx) => {
36+
exports.UserRoles = (0, common_1.createParamDecorator)((propertyKey, ctx) => {
3637
const user = userFactory(ctx);
37-
return data ? user[data] : user.roles;
38+
if (!user)
39+
return null;
40+
return propertyKey ? user[propertyKey] : user.roles;
3841
});

lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
"accesscontrol": "^2.2.1"
5252
},
5353
"peerDependencies": {
54+
"graphql": "15.0.0",
5455
"@apollo/gateway": "^0.45.1",
5556
"@nestjs/graphql": "^7.6.18",
5657
"apollo-server-core": "^3.6.1",
57-
"graphql": "15.0.0",
5858
"ts-morph": "^13.0.2"
5959
}
6060
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nest-access-control",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "Access Control Module For Nestjs Framework",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)