admin管理员组文章数量:1402783
I am trying my hands on Nestjs and i was a bit confused about the req.user. Where do we get this from and do we need to manually req.user? what actually is req.user and what benefit can we have from it? Do i need to assign payload to it manually?
I have tried searching stackoverflow and nestjs documentaion but did not get a clear insight.
import { createParamDecorator } from '@nestjs/mon';
export const User = createParamDecorator((data, req) => req.user);
Like in this example where do i get the req from??
I am trying my hands on Nestjs and i was a bit confused about the req.user. Where do we get this from and do we need to manually req.user? what actually is req.user and what benefit can we have from it? Do i need to assign payload to it manually?
I have tried searching stackoverflow and nestjs documentaion but did not get a clear insight.
import { createParamDecorator } from '@nestjs/mon';
export const User = createParamDecorator((data, req) => req.user);
Like in this example where do i get the req from??
Share Improve this question asked Mar 29, 2021 at 4:14 user15188165user15188165 1- this is an old API (nestjs v6). Please read this: docs.nestjs./custom-decorators and this migration guide – Micael Levi Commented Mar 29, 2021 at 4:20
1 Answer
Reset to default 5req.user
is nothing but a custom key of req
object.
Which can be inserted from any route by pointing req
object.
But generally, it is inserted from the authorization middleware where we pare user by the token. (JWT).
So req.user
can be accessible in all the root where authorization middleware is called.
Note: You can put any data in it and also with a different key like req.body.yourKey
本文标签: javascriptwhat is requser and where is it populated fromStack Overflow
版权声明:本文标题:javascript - what is req.user and where is it populated from? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744328614a2600851.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论