mirror of
https://github.com/khairul169/garage-webui.git
synced 2026-09-15 08:53:21 +07:00
feat: add authentication
This commit is contained in:
@@ -1,5 +1,22 @@
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { Navigate, Outlet } from "react-router-dom";
|
||||
|
||||
const AuthLayout = () => {
|
||||
return <div>AuthLayout</div>;
|
||||
const auth = useAuth();
|
||||
|
||||
if (auth.isLoading) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (auth.isAuthenticated) {
|
||||
return <Navigate to="/" replace />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-svh flex items-center justify-center">
|
||||
<Outlet />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AuthLayout;
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { PageContext } from "@/context/page-context";
|
||||
import { Suspense, useContext, useEffect } from "react";
|
||||
import { Outlet, useLocation, useNavigate } from "react-router-dom";
|
||||
import { Navigate, Outlet, useLocation, useNavigate } from "react-router-dom";
|
||||
import Sidebar from "../containers/sidebar";
|
||||
import { ArrowLeft, MenuIcon } from "lucide-react";
|
||||
import Button from "../ui/button";
|
||||
import { useDisclosure } from "@/hooks/useDisclosure";
|
||||
import { Drawer } from "react-daisyui";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
|
||||
const MainLayout = () => {
|
||||
const sidebar = useDisclosure();
|
||||
const { pathname } = useLocation();
|
||||
const auth = useAuth();
|
||||
|
||||
useEffect(() => {
|
||||
if (sidebar.isOpen) {
|
||||
@@ -17,6 +19,14 @@ const MainLayout = () => {
|
||||
}
|
||||
}, [pathname]);
|
||||
|
||||
if (auth.isLoading) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!auth.isAuthenticated) {
|
||||
return <Navigate to="/auth/login" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Drawer
|
||||
open={sidebar.isOpen}
|
||||
|
||||
Reference in New Issue
Block a user