diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index 170596b..1c480b5 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -1,13 +1,25 @@ -import Login from "./login" +import Login from "./login"; +import { useGo, useIsAuthenticated } from "@refinedev/core"; +import { useEffect } from "react"; export default function Index() { - const isLogged = false + const { isLoading, data } = useIsAuthenticated(); - if (isLogged) { - window.location.href = "/dashboard" - } else { - window.location.href = "/login" + const go = useGo(); + + useEffect(() => { + if (!isLoading && data?.authenticated) { + go({ to: "/dashboard", type: "replace" }); + } + }, [isLoading, data]); + + if (isLoading) { + return <>Checking Login Status || null; } - return isLogged ?
Dashboard
: + if (data?.authenticated) { + return <>Redirecting || null; + } + + return ; }