JWT: How to access it after using UseGuards?
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[ ] Feature request
[ x ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
I have no idea how to access a JWT token and it’s missing in doc/github example.
Let’s take this one: https://github.com/nestjs/nest/blob/master/sample/19-auth/src/auth/auth.controller.ts#L16
Here, we’re securing the route:
@Get('data')
@UseGuards(AuthGuard('jwt'))
findAll() {
// this route is restricted
}
But how can we have access to the current JWT (to retrieve user id or email for example).
Environment
Nest version: 5.0.0
For Tooling issues:
- Node version: 8.9.4
- Platform: Linux
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
Authentication | NestJS - A progressive Node.js framework
For this use case, clients will start by authenticating with a username and password. Once authenticated, the server will issue a JWT that...
Read more >Getting User Data by using Guards (Roles, JWT)
It works since I use @UseGuards(AuthGuard('jwt'), RolesGuard) as decorator. I extending AuthGuard for my RolesGuard and overwriting the ...
Read more >How to implement JWT authentication in NestJS
For this demonstration, we'll use Yarn. Terminal Yarn. Choose yarn and press the Enter key. Now, wait while Yarn installs all the ...
Read more >How to implement NestJS JWT Authentication using JWT ...
In this post, we will learn how to implement NestJS JWT Authentication using Passport JWT Strategy. JWT stands for JSON Web Tokens.
Read more >NestJS JWT Authentication with Refresh Tokens Complete ...
We're using MongoDB as the database for our application. ... We did that so we can access it when we need to refresh...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If you don’t pass any options to auth guard, you should have access to the user by calling req.user
Thanks @maxime1992 . Everything suddenly understood, after seeing
export const Usr = createParamDecorator((data,req)=> req.user);
This is a huge help for me, thanks again.