Open lizhihui888 opened 4 months ago
I want to get user info from jwt token in controller , like this:
@Get('getUser') getUser(@User() user) { return user; }
so I create a custom param decorator like this:
export const User = createParamDecorator((data: string, ctx: ExecutionContext) => { const request = ctx.switchToHttp().getRequest<Request>(); const arr = request.headers.authorization?.split(' ') ?? []; const token = arr.at(-1); if (!token) { return undefined; } // how to inject jwtService ? const payload = jwtService.verify(token); return payload; });
how to inject jwtService into the decorator ? thanks !
Have you found a solution now having the same problem with my custom decorator.
This has nothing to do with the awesome-nestjs repository
Try the following instead:
nestjs
I want to get user info from jwt token in controller , like this:
so I create a custom param decorator like this:
how to inject jwtService into the decorator ? thanks !