fix: Move OIDC redirect to useEffect

This commit is contained in:
Tom Moor
2026-05-08 17:53:33 -04:00
parent 571463710e
commit d3defd3da3
+21 -10
View File
@@ -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 (