refactor: integrate auth provider

This commit is contained in:
Derrick Hammer 2024-03-13 09:40:25 -04:00
parent 552bf84247
commit 427bdbb407
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 19 additions and 7 deletions

View File

@ -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() { export default function Index() {
const isLogged = false const { isLoading, data } = useIsAuthenticated();
if (isLogged) { const go = useGo();
window.location.href = "/dashboard"
} else { useEffect(() => {
window.location.href = "/login" if (!isLoading && data?.authenticated) {
go({ to: "/dashboard", type: "replace" });
}
}, [isLoading, data]);
if (isLoading) {
return <>Checking Login Status</> || null;
} }
return isLogged ? <div>Dashboard</div> : <Login /> if (data?.authenticated) {
return <>Redirecting</> || null;
}
return <Login />;
} }