Logout from Auth0 SPA

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 listed return URL  
10:   this.auth0.logout({ returnTo: "http://localhost:3000/home" });  
11: }  

2. White list the return URL in the Auth0 Dashboard. 
White list callback url in Auth0


And that's it logout will start to work as I (and probably you) expected.  


Comments

Popular posts from this blog

Solving `Empty reply from server` in DotNet Core

Building a verify JWT function in TypeScript

Can't resolve DNS Aws