refactor: switch to using Authenticated and Navigate components

This commit is contained in:
Derrick Hammer 2024-03-20 13:26:41 -04:00
parent 33decc2e2d
commit 6fbbe4975c
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 9 additions and 21 deletions

View File

@ -1,24 +1,12 @@
import {useGo, useIsAuthenticated} from "@refinedev/core";
import {useEffect} from "react";
import {Authenticated} from "@refinedev/core";
import {Navigate} from "@remix-run/react";
export default function Index() {
const {isLoading, data} = useIsAuthenticated();
const go = useGo();
useEffect(() => {
if (!isLoading) {
if (data?.authenticated) {
go({to: "/dashboard", type: "replace"});
} else {
go({to: "/login", type: "replace"});
}
}
}, [isLoading, data]);
if (isLoading) {
return <>Checking Login Status</> || null;
}
return (<>Redirecting</>) || null;
return (
<Authenticated v3LegacyAuthProviderCompatible key={"index"} loading={
<>Checking Login Status</>
}>
<Navigate to="/dashboard" replace/>
</Authenticated>
)
}