redirecting after logout with Auth0
Asked Answered
T

3

7

so I recently got the login button to work with a netlify domain and now when I try to click the logout button, I get redirected to localhost:3000 but I want it to be redirected back to the page with the login button, is there a way to do that? here are my details for the URIs:

Allowed callback URLs:

http://localhost:3000,https://auth0-sample-authentication.netlify.app

Allowed Logout URLs

http://localhost:3000,https://auth0-sample-authentication.netlify.app

Allowed Web Origins

http://localhost:3000,https://auth0-sample-authentication.netlify.app

Please tell me if I need to include more code

Thanks,

324hz win21H2 he/him

Titustityus answered 4/6, 2022 at 20:25 Comment(0)
B
1

If I understand you correctly, you need to add returnTo. It is said in docs https://auth0.com/docs/quickstart/spa/react/01-login

Buckwheat answered 4/6, 2022 at 20:29 Comment(3)
Where would I put a returnTo? because I saw that a bunch of times in docs but I have no clue where I would put itTitustityus
Oh wait I just realized its in the docsTitustityus
community.auth0.com/t/… Here is exampleBuckwheat
N
8

To anyone looking at this question now you might be getting a typescript error with the above selected answer. You need to wrap the returnTo in a logoutParams object.

<button onClick={() => logout({ logoutParams: { returnTo: window.location.origin } })}>
  Log Out
</button>
Ninny answered 19/4, 2023 at 9:15 Comment(0)
B
1

If I understand you correctly, you need to add returnTo. It is said in docs https://auth0.com/docs/quickstart/spa/react/01-login

Buckwheat answered 4/6, 2022 at 20:29 Comment(3)
Where would I put a returnTo? because I saw that a bunch of times in docs but I have no clue where I would put itTitustityus
Oh wait I just realized its in the docsTitustityus
community.auth0.com/t/… Here is exampleBuckwheat
T
0

The answer:
So it looks like all you have to do is in the button tag for the logout button you have to add this line here:

({ returnTo: "https://324hz.dev" })

so that the button looks something like this: (keep in mind this might not be your button layout)

<button onClick={() => logout({ returnTo: "example.com" })}>Log Out</button>

Where "example.com" is the address to the redirect.

Titustityus answered 4/6, 2022 at 22:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.