Auth0 Home Blog Docs

Logout is not deleting cookie on my Angular app

When the user logout, and then login, is does not prompt the login screen. The user is automatically logged in without having to authenticate again.
I am following exactly the instructions of this guide: https://auth0.com/docs/quickstart/spa/angular2#finish-the-service

Here is the logout method I am calling:

public logout(): void {
// Remove tokens and expiry time
this._accessToken = '';
this._idToken = '';
this._expiresAt = 0;
// Remove isLoggedIn flag from localStorage
localStorage.removeItem('isLoggedIn');
// Go back to the home route
this.router.navigate(['/']);

}

What could be wrong?

I am attaching a HAR file that recorded the login, logout and login (without the authorization screen) issue.

PS: The logout works in making the user lose its authentication. But it seems to not delete the cookie / token and re-authenticates the user on login without asking for credentials again.

Here is a recording of the problem happening: https://drive.google.com/file/d/1thkTGOnmTW8bqwqO3CWARIOAPmUVtZCY/view?usp=sharing

I am having the exact same issue as you. Please any help here!.

Hey there @leongrin and @cahergil, I will take a look into the data you shared and let you know what I find. Thanks!

I added this code to my logout method, and it worked for me:

    this.auth0.logout({
returnTo: "MY_LOGOUT_URL",
client_id: "MY_CLIENT_ID"
});

My logout method is now like this:

public logout(): void {
// Remove tokens and expiry time
this._accessToken = '';
this._idToken = '';
this._expiresAt = 0;
// Remove isLoggedIn flag from localStorage
localStorage.removeItem('isLoggedIn');
// Go back to the home route
this.router.navigate(['/']);
this.auth0.logout({
returnTo: 'http://localhost:4200',
client_id: 'MY_CLIENT_ID'

});
}

2 Likes

The above is the correct solution: calling the logout method, which logs the user out of the authorization server and ends their Auth0 session. We will work on getting the applicable Quick Start instructions updated to make sure they include this!

2 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.