nest-access-control 2.1.1 → 3.0.0

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/README.md CHANGED
@@ -97,12 +97,11 @@ We need to build a Video service so users can share there videos with others, bu
97
97
  providers: [AppService],
98
98
  })
99
99
  export class AppModule {}
100
- ```
101
-
102
- Until now everything is fine, but let's make our application,
103
- assume that we have list of video names, user can - _according to our roles_ - `create:own` new video, and `read:any` video, so let's build it:
104
100
  ```
105
101
 
102
+ Until now everything is fine, but let's make our application,
103
+ assume that we have list of video names, user can - _according to our roles_ - `create:own` new video, and `read:any` video, so let's build it:
104
+
106
105
  ```ts
107
106
  // app.controller.ts
108
107
  ...
@@ -23,8 +23,16 @@ let ACGuard = class ACGuard {
23
23
  this.roleBuilder = roleBuilder;
24
24
  }
25
25
  async getUser(context) {
26
- const request = context.switchToHttp().getRequest();
27
- return request.user;
26
+ const contextType = context.getType().toString();
27
+ switch (contextType) {
28
+ case 'http':
29
+ return context.switchToHttp().getRequest().user;
30
+ case 'graphql':
31
+ const { GqlExecutionContext } = require('@nestjs/graphql');
32
+ return GqlExecutionContext.create(context).getContext().req.user;
33
+ default:
34
+ throw new Error(`Unsupported context type: ${contextType}`);
35
+ }
28
36
  }
29
37
  async getUserRoles(context) {
30
38
  const user = await this.getUser(context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nest-access-control",
3
- "version": "2.1.1",
3
+ "version": "3.0.0",
4
4
  "description": "Access Control Module For Nestjs Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -51,7 +51,7 @@
51
51
  "accesscontrol": "^2.2.1"
52
52
  },
53
53
  "peerDependencies": {
54
- "@nestjs/graphql": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0"
54
+ "@nestjs/graphql": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0"
55
55
  },
56
56
  "peerDependenciesMeta": {
57
57
  "@nestjs/graphql": {