From the course: React: Authentication
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Adding log-out functionality - React.js Tutorial
From the course: React: Authentication
Adding log-out functionality
- [Instructor] All right, so the last thing that we have to do here, as I said, is implement some logout functionality. So let's go into our UserInfoPage and we can also close most of these here too. So we'll just close all of those like so, and open our UserInfoPage back up. And now all we have to do is go back down to the logOut function that's already in here and basically just rewrite it so that it logs the user out. Now this is pretty easy to do. All we really have to do is remove, and oops, that's the wrong one there. All we really need to do is remove the token from localStorage and send the user back to the login route, right? We're just going to automatically redirect the user there. So here's what this is going to look like. All we really have to do is call setToken here. And we're going to set that to undefined, right? That's going to remove it from the state anyway. And we might also want to open up a TokenContext here and basically add a case for that. So we'll say, if…
Contents
- What is user authentication?6m 48s
- Basic project setup3m 20s
- (Locked)Creating private React routes8m 17s
- (Locked)JSON Web Token basics11m 29s
- (Locked)Solution: Working with JSON Web Tokens2m 43s
- (Locked)Adding a sign-up route to the server12m 20s
- (Locked)Generating JSON Web Tokens6m 9s
- (Locked)Adding a log-in route to the server4m 32s
- (Locked)Adding JWTs to the front-end4m 19s
- (Locked)Parsing JWT data4m 29s
- (Locked)Adding JWTs to sign-up and log-in pages5m 37s
- (Locked)Adding JWTs to the user info page9m 54s
- (Locked)Adding an "update user" route11m 47s
- (Locked)Adding update functionality to the front-end4m 49s
- (Locked)State management for tokens7m 18s
- (Locked)Adding log-out functionality3m 47s