feat: proper redirect handling

This commit is contained in:
2025-05-29 14:17:09 +02:00
parent 8364a8e9ec
commit 807d7538a0
10 changed files with 106 additions and 53 deletions

View File

@ -28,19 +28,28 @@ const AuthLayout = () => {
const isAuthPage = useMemo(() => {
const allowedPaths = ["/login", "/register", "/authorize"];
if (!allowedPaths.some((p) => location.pathname.startsWith(p))) {
return false;
}
return true;
return allowedPaths.some((p) => location.pathname.startsWith(p));
}, [location.pathname]);
const loading = useMemo(() => {
if (isAuthPage) {
return connecting;
}
return (!hasAuthenticated || !hasLoadedAccounts) || loadingAccounts || authenticating || connecting;
}, [isAuthPage, hasAuthenticated, hasLoadedAccounts, loadingAccounts, authenticating, connecting]);
return (
!hasAuthenticated ||
!hasLoadedAccounts ||
loadingAccounts ||
authenticating ||
connecting
);
}, [
isAuthPage,
hasAuthenticated,
hasLoadedAccounts,
loadingAccounts,
authenticating,
connecting,
]);
useEffect(() => {
connect();
@ -59,10 +68,11 @@ const AuthLayout = () => {
}, [activeAccount, dbConnected, authenticate, loadingAccounts]);
useEffect(() => {
if (!signInRequired && location.state?.from) {
navigate(location.state.from, { state: {} });
if (!signInRequired && isAuthPage) {
const to = location.state?.from ?? "/";
navigate(to, { state: { reset: true } });
}
}, [location.state, location.state?.from, navigate, signInRequired]);
}, [isAuthPage, location.state?.from, navigate, signInRequired]);
if (signInRequired && !isAuthPage) {
return (