This commit is contained in:
Jonas Bengtsson
2026-09-19 09:40:24 +02:00
parent ee4800993d
commit 19bccce083
13 changed files with 435 additions and 43 deletions
+6 -2
View File
@@ -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>;
}