🚧 WIP
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { NavLink, Navigate, Route, Routes } from "react-router-dom";
|
||||
import { NavLink, Navigate, Route, Routes, useLocation } from "react-router-dom";
|
||||
import { useAuth } from "./auth";
|
||||
import { LoginPage } from "./pages/Login";
|
||||
import { ClientsPage } from "./pages/Clients";
|
||||
@@ -30,8 +30,12 @@ function Layout({ children }: { children: React.ReactNode }) {
|
||||
|
||||
function Protected({ children }: { children: React.ReactNode }) {
|
||||
const { session, loading } = useAuth();
|
||||
const location = useLocation();
|
||||
if (loading) return <p>Loading…</p>;
|
||||
if (!session) return <Navigate to="/login" replace />;
|
||||
if (!session) {
|
||||
// Remember the guarded route so Login can return here after sign-in.
|
||||
return <Navigate to="/login" replace state={{ from: location.pathname }} />;
|
||||
}
|
||||
return <Layout>{children}</Layout>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user