Docs for logout seem stale
nipunn1313 opened this issue · 2 comments
Checklist
- The issue can be reproduced in the auth0-react sample app (or N/A).
- I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- I have looked into the API documentation and have not found a suitable solution or answer.
- I have searched the issues and have not found a suitable solution or answer.
- I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- I agree to the terms within the Auth0 Code of Conduct.
Description
/**
* ```js
* auth0.logout({ returnTo: window.location.origin });
* ```
*
* Clears the application session and performs a redirect to `/v2/logout`, using
* the parameters provided as arguments, to clear the Auth0 session.
* If the `logoutParams.federated` option is specified, it also clears the Identity Provider session.
* [Read more about how Logout works at Auth0](https://auth0.com/docs/logout).
*/
logout: (options?: LogoutOptions) => Promise<void>;
Notably it recommends
auth0.logout({ returnTo: window.location.origin });
but actually it needs to be
logout({
async openUrl(url) {
await Browser.open({ url })
},
})
or simply
logout()
Reproduction
Here's a component which reproes
function LogoutButton() {
const { logout } = useAuth0()
return (
<button className="btn btn-primary" onClick={() => logout({ returnTo: window.location.origin })}>
Log out
</button>
)
}
Additional context
No response
auth0-react version
2.0.1
React version
18.2.0
Which browsers have you tested in?
Chrome
Thanks for reporting this. The code sample for logout in the jsdocs is incorrect and for v2 it should be:
auth0.logout({
logoutParams: {
returnTo: '...'
}
})
You can use returnTo to tell Auth0 where it should redirect back to, after logging out.
I opened a PR to fix that code sample, but for the rest, the docs seem to be still accurate.
As you are using Browser.open(), are you using Capacitor's browser? If so, we have specific guidance for integrating the SDK with Capacitor's browser here : https://auth0.com/docs/quickstart/native/ionic-react
nope! I filed the task before I got it fully working (I was just fiddling autocomplete).
Ended up being exactly what you described!
auth0.logout({
logoutParams: {
returnTo: '...'
}
})