From 33decc2e2d034a7f89d1b36dcb89204ae4e14b46 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 20 Mar 2024 13:19:53 -0400 Subject: [PATCH] Revert "fix: route redirection issue" This reverts commit 9a8a7ee97817621f7a4378b25ef9c8b048b81f99. --- app/routes/_index.tsx | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index 150bb68..666f9ca 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -1,19 +1,24 @@ -import { useGo, useIsAuthenticated } from "@refinedev/core"; +import {useGo, useIsAuthenticated} from "@refinedev/core"; +import {useEffect} from "react"; export default function Index() { - const { isLoading, data } = useIsAuthenticated(); + const {isLoading, data} = useIsAuthenticated(); - const go = useGo(); + const go = useGo(); - if (isLoading) { - return <>Checking Login Status; - } + useEffect(() => { + if (!isLoading) { + if (data?.authenticated) { + go({to: "/dashboard", type: "replace"}); + } else { + go({to: "/login", type: "replace"}); + } + } + }, [isLoading, data]); - if (data?.authenticated) { - go({ to: "/dashboard", type: "replace" }); - } else { - go({ to: "/login", type: "replace" }); - } + if (isLoading) { + return <>Checking Login Status || null; + } - return <>Redirecting; + return (<>Redirecting) || null; }