# Redirect to calback URL after Logout

**URL:** <https://community.auth0.com/t/redirect-to-calback-url-after-logout/150175>\
**Category:** Get Help\
**Tags:** sessions, logout\
**Created:** [October 21, 2024, 9:18am UTC](https://community.auth0.com/t/redirect-to-calback-url-after-logout/150175 "2024-10-21T09:18:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![t.fukao](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/t.fukao/32/61052_2.png) [@t.fukao](https://community.auth0.com/u/t.fukao)\
**Post date:** [October 21, 2024, 9:18am UTC](https://community.auth0.com/t/redirect-to-calback-url-after-logout/150175/1 "2024-10-21T09:18:05Z")

</div>

I’m trying to implement a function that logs out from both the application session layer and the Auth0 session layer.

I’m using Auth0 Vue SDK.  
With the logout implementation below, only the application session was cleared, leaving the Auth0 session intact. As a result, if the user reopened the universal login screen, they would be automatically logged in, which is a critical flaw.

```auto
  await auth0.logout({
    logoutParams: {
      returnTo: redirectUrl(),
    },
  });

```

I referred to [this issue](https://community.auth0.com/t/logging-out-completely/118940/) and [this documentation](https://auth0.github.io/auth0-vue/interfaces/LogoutOptions.html#openUrl).

```auto
const logoutUrl = `https://MY_DOMAIN/v2/logoutreturnTo=MY_LOGIN_PAGE_URL&client_id=MY_CLIENT_ID`

  await auth0.logout({
    openUrl: () => {
      window.location.replace(logoutUrl);
    },
  });

```

However, after logging out, the user is redirected to a different page than the URL specified by `returnTo`.

That different page is the callback URL set as the redirect destination after login.

```auto
  const auth0 = createAuth0({
    authorizationParams: {
      redirect_uri: `https://.../callback/`, // ← This page!
    },
  });

```

After redirected to callback page, subsequently the user is redirected to the `returnTo` page.

This means there’s one unexpected redirect in the logout process.  
`Application page → /logout endpoint → callback URL → returnTo page`

I expect this kind of process.  
`Application page → /logout endpoint → returnTo page`  
( Strangely, sometimes it directly redirects to the `returnTo` page. It behaves as I expected, but it only happens occasionally. )

Is this an expected behavior, or a bug?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [October 21, 2024, 4:58pm UTC](https://community.auth0.com/t/redirect-to-calback-url-after-logout/150175/3 "2024-10-21T16:58:42Z")

</div>

Hi @t.fukao,

I understand you observed an extra redirect when users are logging out.

I have taken a close look at your `const logoutURL` and noticed that your URL was not correctly formed.

It should have the format:  
`https://YOUR_DOMAIN/v2/logout?returnTo=YOUR_LOGIN_PAGE_URL&client_id=YOUR_CLIENT_ID`

I have tested this on my end and confirmed that it works.

Could you give that a try and let me know how it goes?

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![t.fukao](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/t.fukao/32/61052_2.png) [@t.fukao](https://community.auth0.com/u/t.fukao)\
**Post date:** [October 22, 2024, 12:22am UTC](https://community.auth0.com/t/redirect-to-calback-url-after-logout/150175/4 "2024-10-22T00:22:48Z")

</div>

Thank you @rueben.tiow .

I’m sorry, I made a typo when I was raising this issue.  
There is an `?` between `logout` and `returnTo`.

I’m encountering this issue with a correctly formatted URL.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [October 22, 2024, 5:47pm UTC](https://community.auth0.com/t/redirect-to-calback-url-after-logout/150175/5 "2024-10-22T17:47:15Z")

</div>

Hi @t.fukao,

Thanks for the clarification.

Can you review your network activity and verify the request at each stage of the logout flow?

Specifically, ensure that the logout endpoint is called correctly with the `returnTo` query parameter and that no other requests redirect you back to your callback URL.

What you observe seems unusual. During my tests, I was redirected to my `returnTo` URL immediately after calling the `/logout` endpoint.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![t.fukao](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/t.fukao/32/61052_2.png) [@t.fukao](https://community.auth0.com/u/t.fukao)\
**Post date:** [October 23, 2024, 2:01am UTC](https://community.auth0.com/t/redirect-to-calback-url-after-logout/150175/6 "2024-10-23T02:01:47Z")

</div>

Thank you @rueben.tiow .

I’ve checked the network activity.

①  
The status of `logout` endpoint was **canceled**.  
The parameters were set correctly.  
 ![9ae487187b251498679df11a5df3b01c](https://global.discourse-cdn.com/auth0/original/3X/c/8/c80f617304b106a442ac22eea3015fb369af3ba0.png)

②  
After that, `authorize` endpoint was called 4 times.  
They were **canceled** 3 times, and last one returned **302**.  
 ![88d436cc808e7dd41cbf546ce2e553c3](https://global.discourse-cdn.com/auth0/original/3X/f/d/fdc5a6cef0bf6235df5c66751e0320c1b44c8e82.png)

The `redirect_uri` paramater was the callback URL.  
 ![e5148010b6229a827226f4fb7e8b1c4b](https://global.discourse-cdn.com/auth0/original/3X/8/3/8385ccb22ce04fd41cb339836c39cab6937b7ac5.png)

③  
Next, redirected to the callback URL.  
It has the same `state` parameter as `authorize` endpoint did.

④  
Next,the `logout` endpoint was called again.  
The parameters were same as the first step.

⑤  
Finally, redirected to the login page.

* * *

Moreover, I’m having trouble with a number of other strange occurrences.  
After I logged out, I’m redirected to the app’s home page as being authenticated.  
After entering my credentials and clicking the login button in Universal Login Page, I’m redirected to Universal Login Page again and prompted to re-enter my credentials.

I hypothesize that the underlying cause of all problems is a failure to terminate the Auth0 session layer upon logout.

Introducing a few seconds delay using _setTimeout_ before executing `auth0.logout` improved the likelihood of successful logout.

I suspect that third-party cookies or session record on the Auth0 server are being deleted during this delay, but I’m not sure.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [November 26, 2024, 12:09am UTC](https://community.auth0.com/t/redirect-to-calback-url-after-logout/150175/7 "2024-11-26T00:09:15Z")

</div>

Hi @t.fukao,

I recommend reviewing our [Logout](https://auth0.com/docs/authenticate/login/logout) documentation about logging users out on the Auth0 Session Layer. This will require you to call the [`/oidc/logout` endpoint](https://auth0.com/docs/api/authentication#oidc-logout).

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 10, 2024, 12:10am UTC](https://community.auth0.com/t/redirect-to-calback-url-after-logout/150175/8 "2024-12-10T00:10:01Z")

</div>

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