Now that we have our encoded JWT we need to be able to decode it!
The jsonwebtoken
library makes this very easy. All we have to do is pass the jwt
and our token
to a decoder function. In that function definition we pass the arguments into the verify
method and return the result.
Instructor: [0:00] Create a decoded variable that stores the return value of an async function named verifyJWT. This function takes the token to be decoded and the secrets the token was encoded with.
[0:16] Log the decoded value to the console for inspection. Create the verified JWT function and call the verify method from the JSON Web Token library, passing it to JWT and the token secret.
[0:33] Head to the browser and click the Authorize link. Then head to the terminal, and you should see that the decoded values have been printed.
[0:44] If the verification threw an error, it means that either the JWT is invalid, has been messed with, or you have supplied a wrong secret. You can confirm this by passing a random string instead of the token as a secret. Click the Authorize link again, and you should get an error in the console.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!