From the course: React: Authentication

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Adding logout functionality

Adding logout functionality - React.js Tutorial

From the course: React: Authentication

Adding logout functionality

- [Instructor] All right. So at this point, even though it's still quite a simple app, we have a fully functioning authentication flow that allows our users to both create a new account and log in if they have an existing account. However, there is one last thing we have left to implement and that is allowing users to actually log out of our site. Right? If we click on that button now, we still see this alert. Now with JWTs, the way that logging out is usually implemented is simply by deleting the JWT token that we have stored in local storage. So, the code here is actually going to be amazingly simple. What we're going to do is go back to our user info page and scroll down to our log-out function here. And, we're going to remove the code that's in there right now. And, we're simply going to say localstorage.removeItem ('token'). And underneath that, we're going to push the user back to the login page by…

Contents