# Logout does not work in Angular SPA

**URL:** <https://community.auth0.com/t/logout-does-not-work-in-angular-spa/85155>\
**Category:** Get Help\
**Tags:** logout\
**Created:** [June 15, 2022, 10:20am UTC](https://community.auth0.com/t/logout-does-not-work-in-angular-spa/85155 "2022-06-15T10:20:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![petr.smejkal](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/petr.smejkal/32/12872_2.png) [@petr.smejkal](https://community.auth0.com/u/petr.smejkal)\
**Post date:** [June 15, 2022, 10:20am UTC](https://community.auth0.com/t/logout-does-not-work-in-angular-spa/85155/1 "2022-06-15T10:20:39Z")

</div>

Hi!

I have an issue with getting logout working in Angular SPA.

- I use angular auth0 SDK
- We use refresher tokens and cache location = localStorage, because Safari did not hold the login
- The ‘Allowed Logout URLs’ is equal to redirectTo parameter of logout function

Here is the code we are using, very straightforward

```auto
this.authService.logout({returnTo: environment.baseUrl});

```

- Everything seems to be working, the page refreshes and the user is no longer logged in
- However, if I simply reload the page or do login with this.authService.loginWithRedirect(); the user is logged immediatelly back in
- On “logout”, neither cookie nor local storage is cleared at all

What am I doing wrong? Do I need to send the client\_id and localOnly = false when I log out? I don’t believe it is described anywhere, but I will try that.

Thanks

---

<div class="post-metadata">

**Author:** ![petr.smejkal](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/petr.smejkal/32/12872_2.png) [@petr.smejkal](https://community.auth0.com/u/petr.smejkal)\
**Post date:** [June 15, 2022, 10:25am UTC](https://community.auth0.com/t/logout-does-not-work-in-angular-spa/85155/2 "2022-06-15T10:25:00Z")

</div>

I forgot to say:

- I am using latest Angular (14) and SDK (1.10.0)

---

<div class="post-metadata">

**Author:** ![petr.smejkal](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/petr.smejkal/32/12872_2.png) [@petr.smejkal](https://community.auth0.com/u/petr.smejkal)\
**Post date:** [June 15, 2022, 10:37am UTC](https://community.auth0.com/t/logout-does-not-work-in-angular-spa/85155/3 "2022-06-15T10:37:38Z")

</div>

Ok, the addition of client\_id and localOnly to logout did **NOT** help.

```auto
this.authService.logout(
      {
        returnTo: environment.baseUrl,
        // eslint-disable-next-line @typescript-eslint/naming-convention
        client_id: environment.auth0Config.clientId,
        localOnly: false
      }
    );

```

---

<div class="post-metadata">

**Author:** ![petr.smejkal](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/petr.smejkal/32/12872_2.png) [@petr.smejkal](https://community.auth0.com/u/petr.smejkal)\
**Post date:** [June 15, 2022, 2:18pm UTC](https://community.auth0.com/t/logout-does-not-work-in-angular-spa/85155/4 "2022-06-15T14:18:48Z")

</div>

I will also try the last 2 tips from here: [Check Login and Logout Issues](https://auth0.com/docs/troubleshoot/authentication-issues/check-login-and-logout-issues)

Namely

- Make sure that the logout redirect URL is different from the login callback URL.
- Make the logout redirect URL an anonymous page (not protected by login) so that redirects to the logout redirect URL do not immediately trigger a login, which may confuse users.

---

<div class="post-metadata">

**Author:** ![petr.smejkal](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/petr.smejkal/32/12872_2.png) [@petr.smejkal](https://community.auth0.com/u/petr.smejkal)\
**Post date:** [September 2, 2022, 10:34am UTC](https://community.auth0.com/t/logout-does-not-work-in-angular-spa/85155/5 "2022-09-02T10:34:24Z")

</div>

So, it seems the issue was that I had the onClick handler on an anchor element (a) with empty href attribute:

```auto
<a href="" ng-click="authService.logout(...)">Logout</a>

```

At least after changing this to a span element, the issues stopped. So, if anyone has similar issues, you can try this first.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 4, 2022, 2:47pm UTC](https://community.auth0.com/t/logout-does-not-work-in-angular-spa/85155/6 "2022-11-04T14:47:56Z")

</div>


