Posts

Showing posts from September, 2018

Logout from Auth0 SPA

Image
I have been working through some Auth0 tutorials lately to get an understanding of how to implement it in production. One thing that is missing in the Auth0 SPA basic tutorial is how to log the user out. I got a bit panicked when I first used it and didn't see the login screen after logging out.  It's not enough to simply clear the tokens from the local cache you need to call logout on the Auth0 Client. This is all pretty simple once you know it needs to happen. 1. Update the code in the log out method to call logout with the desired return value: 1: logout() { 2: // Clear Access Token and ID Token from local storage 3: localStorage.removeItem("access_token"); 4: localStorage.removeItem("id_token"); 5: localStorage.removeItem("expires_at"); 6: // You don't need navigate to the home route anymore 7: // Auth0 will redirect you 8: // history.replace("/home"); 9: // Call logout with white li