Protect routes
This commit is contained in:
1 parent
6e01fca87d
commit
b79c460077
1 file changed
+8
@@ -2,10 +2,18 @@ import { Outlet } from "react-router";
|
|||||||
import Footer from "./components/Footer/Footer.jsx"
|
import Footer from "./components/Footer/Footer.jsx"
|
||||||
import Header from "./components/Header/Header.jsx";
|
import Header from "./components/Header/Header.jsx";
|
||||||
import Background from "./components/background/background.jsx";
|
import Background from "./components/background/background.jsx";
|
||||||
|
import { Navigate } from "react-router";
|
||||||
|
import { useContext} from "react";
|
||||||
|
import { AuthContext } from "./contexts/auth/AuthContext.js";
|
||||||
|
|
||||||
|
|
||||||
function Layout(){
|
function Layout(){
|
||||||
|
|
||||||
|
const { user, loading } = useContext(AuthContext);
|
||||||
|
|
||||||
|
if (loading) return <p>Loading</p>;
|
||||||
|
if (!user) return <Navigate to="/login" />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Background>
|
<Background>
|
||||||
|
|||||||
Reference in new issue
Block a user