fix(oidcloginbutton): ensure router is initialized in callback hook

This commit is contained in:
Michael Thomas
2026-03-27 13:28:01 -04:00
parent 8fcf764722
commit ba2f5776e7

View File

@@ -50,22 +50,25 @@ export default function OidcLoginButton({
}
}, [provider, intl, onError, router]);
useEffect(() => {
if (loading) return;
useEffect(
() => {
if (!router.isReady || loading) return;
// OIDC provider has redirected back with an authorization code or error
const isCallback = query.code != null || query.error != null;
// OIDC provider has redirected back with an authorization code or error
const isCallback = query.code != null || query.error != null;
if (isCallback && getOidcProviderSlug() === provider.slug) {
clearOidcProviderSlug();
handleCallback();
}
// Support direct redirect via ?provider=slug query param
else if (!isCallback && query.provider === provider.slug) {
redirectToLogin();
}
if (isCallback && getOidcProviderSlug() === provider.slug) {
clearOidcProviderSlug();
handleCallback();
}
// Support direct redirect via ?provider=slug query param
else if (!isCallback && query.provider === provider.slug) {
redirectToLogin();
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
[router.isReady]
);
return (
<ButtonWithLoader