From the course: React: Authentication (2021)
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Generating JSON Web Tokens - React.js Tutorial
From the course: React: Authentication (2021)
Generating JSON Web Tokens
- [Instructor] Okay, so the last thing we're going to want to do here is generate a JSON Web Token with all of this information, except for the passwordHash that we're going to basically send back to the client so that they can store it and use it. So what that's going to look like, we're going to use the jwt.sign method from the JSON Web Token package we installed. And basically what we need to do is pass this an argument containing all of the data we want to include in the web token. So we're going to want to include the user's ID in the database, which is the insertedId thing we just defined there. We're going to send back their email, their info, which again is going to be startingInfo and we're going to send back isVerified, which is going to be false. Okay? So that's the first argument is the data we want to include in the token. The second argument here is going to be the JSON Web Token secret. And basically…
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
-
-
-
-
-
-
-