JWT gives JsonWebTokenError "invalid token"

I had the same issue. Basically the token should not have brearer information. When I stripped it out it started working as expected.

For instance:

Failed when I used brearer *************....

Worked when I used *************....


If you are passing in a token to your jwt.verify function like so Bearer *************...., ensure to split the token first before passing it in to jwt by doing

const token = req.headers.authorization.split(' ')[1]; jwt.verify(token)

Hope this helps someone.


My Code is true . The mistake I was doing that I was giving access token with double quote("token") in Postman. That's why postman was giving me following error

"auth": false, "message": { "name": "JsonWebTokenError", "message": "invalid token" } }