Compare commits

...

2 Commits

Author SHA1 Message Date
Stavros
ff771c5c22 fix: use the href of the url object instead of the object iself as the
dep in the callback
2026-02-15 19:55:37 +02:00
Nicolas Meienberger
d7b00ffeea refactor(continue-page): simplify useEffect to avoid unnecessary dependencies 2026-02-11 18:43:48 +01:00
2 changed files with 36 additions and 35 deletions

3
.gitignore vendored
View File

@@ -39,3 +39,6 @@ __debug_*
# infisical # infisical
/.infisical.json /.infisical.json
# traefik data
/traefik

View File

@@ -32,34 +32,43 @@ export const ContinuePage = () => {
cookieDomain, cookieDomain,
); );
const handleRedirect = useCallback(() => { const urlHref = url?.href;
const hasValidRedirect = valid && allowedProto;
const showUntrustedWarning =
hasValidRedirect && !trusted && !disableUiWarnings;
const showInsecureWarning =
hasValidRedirect && httpsDowngrade && !disableUiWarnings;
const shouldAutoRedirect =
isLoggedIn &&
hasValidRedirect &&
!showUntrustedWarning &&
!showInsecureWarning;
const redirectToTarget = useCallback(() => {
if (!urlHref || hasRedirected.current) {
return;
}
hasRedirected.current = true; hasRedirected.current = true;
window.location.assign(urlHref);
}, [urlHref]);
const handleRedirect = useCallback(() => {
setIsLoading(true); setIsLoading(true);
window.location.assign(url!); redirectToTarget();
}, [url]); }, [redirectToTarget]);
useEffect(() => { useEffect(() => {
if (!isLoggedIn) { if (!shouldAutoRedirect) {
return;
}
if (hasRedirected.current) {
return;
}
if (
(!valid || !allowedProto || !trusted || httpsDowngrade) &&
!disableUiWarnings
) {
return; return;
} }
const auto = setTimeout(() => { const auto = setTimeout(() => {
handleRedirect(); redirectToTarget();
}, 100); }, 100);
const reveal = setTimeout(() => { const reveal = setTimeout(() => {
setIsLoading(false);
setShowRedirectButton(true); setShowRedirectButton(true);
}, 5000); }, 5000);
@@ -67,18 +76,7 @@ export const ContinuePage = () => {
clearTimeout(auto); clearTimeout(auto);
clearTimeout(reveal); clearTimeout(reveal);
}; };
}, [ }, [shouldAutoRedirect, redirectToTarget]);
isLoggedIn,
hasRedirected,
valid,
allowedProto,
trusted,
httpsDowngrade,
disableUiWarnings,
setIsLoading,
handleRedirect,
setShowRedirectButton,
]);
if (!isLoggedIn) { if (!isLoggedIn) {
return ( return (
@@ -89,11 +87,11 @@ export const ContinuePage = () => {
); );
} }
if (!valid || !allowedProto) { if (!hasValidRedirect) {
return <Navigate to="/logout" replace />; return <Navigate to="/logout" replace />;
} }
if (!trusted && !disableUiWarnings) { if (showUntrustedWarning) {
return ( return (
<Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm"> <Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm">
<CardHeader> <CardHeader>
@@ -113,7 +111,7 @@ export const ContinuePage = () => {
</CardHeader> </CardHeader>
<CardFooter className="flex flex-col items-stretch gap-2"> <CardFooter className="flex flex-col items-stretch gap-2">
<Button <Button
onClick={() => handleRedirect()} onClick={handleRedirect}
loading={isLoading} loading={isLoading}
variant="destructive" variant="destructive"
> >
@@ -131,7 +129,7 @@ export const ContinuePage = () => {
); );
} }
if (httpsDowngrade && !disableUiWarnings) { if (showInsecureWarning) {
return ( return (
<Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm"> <Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm">
<CardHeader> <CardHeader>
@@ -150,7 +148,7 @@ export const ContinuePage = () => {
</CardHeader> </CardHeader>
<CardFooter className="flex flex-col items-stretch gap-2"> <CardFooter className="flex flex-col items-stretch gap-2">
<Button <Button
onClick={() => handleRedirect()} onClick={handleRedirect}
loading={isLoading} loading={isLoading}
variant="warning" variant="warning"
> >
@@ -178,7 +176,7 @@ export const ContinuePage = () => {
</CardHeader> </CardHeader>
{showRedirectButton && ( {showRedirectButton && (
<CardFooter className="flex flex-col items-stretch"> <CardFooter className="flex flex-col items-stretch">
<Button onClick={() => handleRedirect()}> <Button onClick={handleRedirect}>
{t("continueRedirectManually")} {t("continueRedirectManually")}
</Button> </Button>
</CardFooter> </CardFooter>