Payload error in jsonwebtoken

后端 未结 7 2057
谎友^
谎友^ 2021-02-01 16:50

I am making a web application using nodejs and angular cli I\'m using JWT to authenticate my login function . But when I process it threw this error

Err

7条回答
  •  离开以前
    2021-02-01 17:39

    I had this problem as well, with a returned user from mongoose, just add toJSON() or toObject() will fix the issue, but what happens if your user is not always coming from mongoose?

    You will get a

    user.toJson/user.ToObject is not a function

    if you try to do this on a plain object.

    If your user is coming from different sources and you don't know if it will be a plain object or not, you can solve it like this:

    JSON.parse(JSON.stringify(user));
    

提交回复
热议问题