nest-access-control 2.1.1 → 2.2.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.
@@ -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": "2.2.0",
4
4
  "description": "Access Control Module For Nestjs Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {