I am trying to implement login system using graphql in nest js.
I have login EP - works fine - returs Bearer token.
But I have query
to get current user:
import { CurrentUser } from '../auth/user.decorator'
.
.
.
@Query()
@UseGuards(JwtAuthGuard)
public async me(@CurrentUser() user: any) {
console.log(user)
return { email: 'foo' }
}
With custom decorator (user.decorator.ts
):
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { GqlExecutionContext } from '@nestjs/graphql';
export const CurrentUser = createParamDecorator(
(data: unknown, context: ExecutionContext) => {
const ctx = GqlExecutionContext.create(context);
return ctx.getContext().req.user;
},
);
When I run me
I am getting an error "host.getArgByIndex is not a function",
- it throw insinde CurrentUser
decorator by ctx.getContext()
... what is wrong?
Is my Import correct?
It it directly from nestjs doc: https://docs.nestjs.com/techniques/authentication