How can I get the current User logged in

Viewed 28

I'm working with Nestjs JWT Graphql

My problem is to affect the name of the current user ( logged in user ) to profile already created by current user
in case of @Query I could get the data of current user as shwon below

@Query((returns) => [CheckSnData])
  @UseGuards(JwtAuthGuard)
  async getAllTPEforAdministrateur(@userToken() user: User) {
    console.log(user);
     if (user.role === ROLE.ADMINISTRATEUR) {
    return this.tpeService.getAllTPEforAdministrateur(user.email);
     }
  }

I tried the same thing with the function create to get the name of current user and affect it to the new user

@Mutation(() => MsTechSoft)
  @UseGuards(JwtAuthGuard)
  createMsTechSoft(
    @Args('userV1') userV1: UserV1,
    @CurrentUser() ms: MsTechSoft,
  ) {
    console.log('CURRENT USER', ms);
    
    console.log('userV1', userV1);

    return this.msTechSoftService.create(userV1);
  }

this is the file of the JwtAuthGuard

import { ExecutionContext, Injectable } from '@nestjs/common';
import { GqlExecutionContext } from '@nestjs/graphql';
import { AuthGuard } from '@nestjs/passport';

@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {
  getRequest(context: ExecutionContext) {
    const ctx = GqlExecutionContext.create(context);
    return ctx.getContext().req;
  }
}

ms ==> undefined
How can I get the current user in mutation query or any one has any idea to get data of current user

0 Answers
Related