From 427bdbb4079656fef3c09f02460186290f4b6483 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 13 Mar 2024 09:40:25 -0400 Subject: [PATCH] refactor: integrate auth provider --- app/routes/_index.tsx | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) 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 ; }