JsonWebTokenError: jwt malformed
Closed this issue · 3 comments
replete commented
Encountered this error while investigating other issues I've been having around this codebase, I am reporting it here as someone had this problem in the other repository.
Environment
- node v16.12.0
- npm 8.1.0
- MongoDB 5.0.3 community edition installed from homebrew
- macos catalina 10.15.7
Repro
git clone git@github.com:TomDoesTech/Testing-Express-REST-API.git
cd Testing-Express-REST-API
npm i
(make sure mongodb is ready)
npm run dev
(send 'Create User' request in Postman)
(successful response in postman:)
{
"email": "test@example.com",
"name": "Jane Doe",
"_id": "6174b21643dd23a0be37c83b",
"createdAt": "2021-10-24T01:08:38.462Z",
"updatedAt": "2021-10-24T01:08:38.462Z",
"__v": 0
}
Then follows this error in the console:
Error
npm run dev
> rest-api-tutorial-updated@1.0.0 dev
> ts-node-dev --respawn --transpile-only src/app.ts
[INFO] 02:08:25 ts-node-dev ver. 1.1.8 (using ts-node ver. 9.1.1, typescript ver. 4.4.3)
[2021-10-24T02:08:27+01:00] INFO: App is running at http://localhost:1337
[2021-10-24T02:08:27+01:00] INFO: DB connected
JsonWebTokenError: jwt malformed
at Object.module.exports [as verify] (/Users/phil/dev/Testing-Express-REST-API/node_modules/jsonwebtoken/verify.js:63:17)
at verifyJwt (/Users/phil/dev/Testing-Express-REST-API/src/utils/jwt.utils.ts:16:25)
at /Users/phil/dev/Testing-Express-REST-API/src/middleware/deserializeUser.ts:22:41
at step (/Users/phil/dev/Testing-Express-REST-API/src/middleware/deserializeUser.ts:33:23)
at Object.next (/Users/phil/dev/Testing-Express-REST-API/src/middleware/deserializeUser.ts:14:53)
at /Users/phil/dev/Testing-Express-REST-API/src/middleware/deserializeUser.ts:8:71
at new Promise (<anonymous>)
at __awaiter (/Users/phil/dev/Testing-Express-REST-API/src/middleware/deserializeUser.ts:4:12)
at deserializeUser (/Users/phil/dev/Testing-Express-REST-API/src/middleware/deserializeUser.ts:9:21)
at Layer.handle [as handle_request] (/Users/phil/dev/Testing-Express-REST-API/node_modules/express/lib/router/layer.js:95:5)
tomanagle commented
Hey @replete, try this: https://youtu.be/FzKrfwplips
replete commented
@tomanagle Cheers Tom, didn't stop me but I was just reporting it here as it probably was tripping other people up.
Erick-Bravo commented
@replete I am not using postman, as demo'd in the video. I am just getting it randomly and my browser is in a refresh loop. Tried going back to working commits but it's still happening. Any suggestions?