feat: proper redirect handling
This commit is contained in:
@ -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 (
|
||||
|
Reference in New Issue
Block a user