我有一个 React 应用程序,每当我注销时,它总是从“允许的注销 URL”重定向到第一个 URL,即使我已在提供程序中指定了 returnTo。
这是我的提供商的代码:
<Auth0Provider
domain="<My domain here>"
clientId="<My clientId here>"
authorizationParams={{
redirect_uri: window.location.origin + window.location.pathname,
audience: '<My audience here>',
scope: 'openid profile email',
}}
logoutParams={{
returnTo: 'http://localhost:3000/logout',
}}
>
那么,假设我的应用程序位于
https://example.com
。我在 Auth0 上的应用程序的 https://localhost:3000/logout, https://example.com/logout
列表中提到了 Allowed Logout URLs
。我还在我的租户级别的高级设置中提到了它们。
我也尝试在致电
returnTo
时提供logout
,如下所示:
const { logout } = useAuth0();
logout({ returnTo: window.location.origin });
我计划在未来的不同网络环境中使用不同的 Auth0 租户,但目前我们在开发环境和临时环境之间只有一个租户。
我已经查看了 Auth0 社区,但到目前为止还没有成功。例如 - https://community.auth0.com/t/auth0-allowed-logout-urls-only-working-with-1st-url-in-the-list/113002
不过,每当我在
https://example.com
上注销时,它都会将我重定向到 https://localhost:3000/logout
,因为这是列表中的第一个 URL。
如何将用户重定向到
https://example.com/logout
而不是本地主机?
不要在 Auth0Provider 组件中静态设置
returnTo
URL,而是尝试根据当前环境动态设置它,就像这样:
<Auth0Provider
domain="<My domain here>"
clientId="<My clientId here>"
authorizationParams={{
redirect_uri: window.location.origin + window.location.pathname,
audience: '<My audience here>',
scope: 'openid profile email',
}}
logoutParams={{
returnTo: window.location.origin + '/logout',
}}
>