I created a new nest 7 project and followed the authentication documentation, but for the graphql the decorator threw an error of undefined when using custom route decorator
GraphQL guard Custom decorator doesn't work.
https://github.com/rained23/nestjs-graphql-decorator
Get JWT
curl -X POST http://localhost:3000/auth/login -d '{"username": "john", "password": "changeme"}' -H "Content-Type: application/json"
{
whoAmI{
username
}
}
TypeError: undefined is not a function
at exports.CurrentUser.common_1.createParamDecorator (/home/me/graphauth/dist/auth/user.decorator.js:4:53)
at shared_utils_1.isFunction.args (/home/me/graphauth/node_modules/@nestjs/core/helpers/context-utils.js:32:28)
at resolveParamValue (/home/me/graphauth/node_modules/@nestjs/core/helpers/external-context-creator.js:141:31)
Should be working because it is from the official documentation
[Nest Platform Information]
platform-express version : 7.0.0
passport version : 7.0.0
graphql version : 7.0.6
common version : 7.0.0
core version : 7.0.0
jwt version : 7.0.0
For Tooling issues:
- Node version: 11.15.00
- Platform: Linux
Others:
Thanks for reporting! Just fixed: https://docs.nestjs.com/techniques/authentication#graphql (update your decorator's code):
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;
},
);
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Thanks for reporting! Just fixed: https://docs.nestjs.com/techniques/authentication#graphql (update your decorator's code):