refactor: integrate auth provider
This commit is contained in:
parent
552bf84247
commit
427bdbb407
|
@ -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 />;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue