From the course: React: Authentication (2021)
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Verifying JSON Web Tokens - React.js Tutorial
From the course: React: Authentication (2021)
Verifying JSON Web Tokens
- [Instructor] So now that we have our JSON Web Token, we need to actually verify that it hasn't been tampered with. And the way we can do that is by using the JSON Web Token packages verify method. So we're going to say JWT.verify. We're going to pass the token as the first argument. The second argument is going to be our secret process.env.JWT Secret. And after that, we have our callback which is going to have to be asynchronous, you'll see why in just a minute. And the two arguments here are going to be an error, if one occurred and the decoded JSON object. All right, so that should be our user. So just like we've seen before. First thing we're going to do is check if there was an error, if there was an error, chances are that means that the token was not intact, right? It had been tampered with in some way or just wasn't valid anymore. So in that case, we'll return a response with a status of 401, meaning the user…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
What is user authentication?6m 27s
-
(Locked)
Basic project setup6m 28s
-
(Locked)
Building a login page8m 54s
-
(Locked)
Building a sign-up page4m 36s
-
(Locked)
Creating private React routes4m 11s
-
JSON Web Token basics9m 22s
-
(Locked)
Adding a sign-up route to the server8m 10s
-
(Locked)
Generating JSON Web Tokens6m 10s
-
(Locked)
Adding a login route to the server6m 59s
-
(Locked)
Implementing JWTs on the front end7m 36s
-
(Locked)
Adding JWTs to sign-up page4m 29s
-
(Locked)
Adding JWTs to login page2m 11s
-
(Locked)
Adding an update user route6m 22s
-
(Locked)
Verifying JSON Web Tokens5m 17s
-
(Locked)
Adding JWTs to the user info page7m 29s
-
(Locked)
Adding logout functionality1m 33s
-
-
-
-
-
-
-