title: how to implement user guards in nestjs graphql
body: <p>I'm trying to get the current user but in the resolver I get undefined, in the jwt strategy I get the user object using the token but in the resolver the user is undefined</p>
  <p><em>auth guard</em></p>
  <pre><code>import { ExecutionContext, Injectable } from '@nestjs/common';
  import { AuthGuard } from '@nestjs/passport';
  import { GqlExecutionContext } from '@nestjs/graphql';
  import { AuthenticationError } from 'apollo-server-core';
  import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host';
  
  @Injectable()
  export class GqlAuthGuard extends AuthGuard('jwt') {
  
      canActivate(context: ExecutionContext) {
          const ctx = GqlExecutionContext.create(context);
          const { req } = ctx.getContext();
  
          return super.canActivate(
              new ExecutionContextHost([req]),
          );
      }
  
      handleRequest(err: any, user: any) {
          if (err || !user) {
              throw err || new AuthenticationError('GqlAuthGuard');
          }
          return user;
      }
  
  }
  
  </code></pre>
  <p><em>user decorator</em></p>
  <pre><code>import {createParamDecorator} from '@nestjs/common';
  
  export const CurrentUser = createParamDecorator(
      (data, req) =&gt;  req.user )
  ;
  </code></pre>
  <p><em>app module</em></p>
  <pre><code>@Module({
    imports: [
        PassportModule.register({ defaultStrategy: 'jwt' }),
        JwtModule.register({
            signOptions: {
                expiresIn: 3600,
            },
        }),
        SharedModule,
        AuthModule,
        GraphQLModule.forRoot({
            autoSchemaFile: 'schema.gql',
            context: ({ req }) =&gt; ({ req })
        }),
        MongooseModule.forRoot(process.env.MONGO_URI,
          {
            useNewUrlParser: true ,
            useUnifiedTopology: true
          }),
      // RewardsModule,
      OrdersModule,
    ],
    controllers: [AppController],
    providers: [AppService],
  })
  export class AppModule {}
  </code></pre>
  <p><em>resolver</em></p>
  <pre><code>import {User} from &quot;src/types/user&quot;;
  import {GqlAuthGuard} from &quot;../guards/graphql.auth.guard&quot;;
  
  @Resolver()
  export class OrdersResolver {
      constructor(
          private orderService: OrdersService
      ) {
      }
  
      @Query(returns =&gt; [Order])
      @UseGuards(GqlAuthGuard)
      listOrders(@CurrentUser() user: User): Promise&lt;Order&gt; {
          console.log(user)
          return this.orderService.listOrdersByUser(user.id);
      }
  
  }
  </code></pre>
  <p>I also tried to implement the solution explained here <a href="https://stackoverflow.com/questions/55269777/nestjs-get-current-user-in-graphql-resolver-authenticated-with-jwt">NestJS Get current user in GraphQL resolver authenticated with JWT</a> and still, I got the same error</p>