mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
fix: Move OIDC redirect to useEffect (#12301)
This commit is contained in:
+21
-10
@@ -70,6 +70,23 @@ function Login({ children, onBack }: Props) {
|
||||
);
|
||||
const [lastVisitedPath] = useLastVisitedPath();
|
||||
const [spendPostLoginPath] = usePostLoginPath();
|
||||
const hasRedirectedToOidc = React.useRef(false);
|
||||
|
||||
const shouldRedirectToOidc =
|
||||
!auth.authenticated &&
|
||||
!auth.isFetching &&
|
||||
config?.providers.length === 1 &&
|
||||
config.providers[0].id === "oidc" &&
|
||||
!env.OIDC_DISABLE_REDIRECT &&
|
||||
!query.get("notice") &&
|
||||
!query.get("logout");
|
||||
|
||||
React.useEffect(() => {
|
||||
if (shouldRedirectToOidc && !hasRedirectedToOidc.current && config) {
|
||||
hasRedirectedToOidc.current = true;
|
||||
window.location.href = getRedirectUrl(config.providers[0].authUrl);
|
||||
}
|
||||
}, [shouldRedirectToOidc, config]);
|
||||
|
||||
const handleReset = React.useCallback(() => {
|
||||
setEmailLinkSentTo("");
|
||||
@@ -270,16 +287,10 @@ function Login({ children, onBack }: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
// If there is only one provider and it's OIDC, redirect immediately.
|
||||
if (
|
||||
config.providers.length === 1 &&
|
||||
config.providers[0].id === "oidc" &&
|
||||
!env.OIDC_DISABLE_REDIRECT &&
|
||||
!query.get("notice") &&
|
||||
!query.get("logout")
|
||||
) {
|
||||
window.location.href = getRedirectUrl(config.providers[0].authUrl);
|
||||
return null;
|
||||
// If there is only one provider and it's OIDC, the redirect is performed
|
||||
// from the effect above – render a loading indicator while we wait.
|
||||
if (shouldRedirectToOidc) {
|
||||
return <LoadingIndicator />;
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user