NodeJs - Retrieve user infor from JWT token?

前端 未结 4 544
天涯浪人
天涯浪人 2020-12-06 00:19

Node and Angular. I have a MEAN stack authentication application where I am setting a JWT token on successful login as follows, and storing it in a session in the controller

4条回答
  •  庸人自扰
    2020-12-06 00:34

    According to the documentation https://github.com/themikenicholson/passport-jwt, you could use request.user. Note, I'm supposing that you are using passport with passport-jwt. It's possible because passport during the context of an authentication is setting the request object and populating the user property. So, just access that property. You don't need to do a middleware.

提交回复
热议问题