Disallow access to /admin if user is not admin

This commit is contained in:
T'JAMPENS QUENTIN p2406187
2025-12-10 12:15:52 +01:00
parent c1a7db12e3
commit 2dd2cd2d4b
2 changed files with 12 additions and 2 deletions
+1
View File
@@ -14,6 +14,7 @@ export function AuthProvider({ children }) {
const u = await getUser();
setUser(u);
setLoading(false);
console.log(u);
})();
}, []);
+11 -2
View File
@@ -1,17 +1,26 @@
import React, { useState } from "react";
import React, { useState, useEffect, useContext } from "react";
import { Doughnut } from "react-chartjs-2";
import { Chart, ArcElement } from "chart.js";
import styles from "./StatPage.module.css";
import Button from "./../../components/ui/button/button";
import { AuthContext } from "../../contexts/auth/AuthContext.js";
import { useNavigate } from "react-router";
// Enregistrer les éléments nécessaires
Chart.register(ArcElement);
function StatPage() {
const { user } = useContext(AuthContext);
const navigate = useNavigate();
const [months, setMonths] = useState(3);
const [participationRate, setParticipationRate] = useState(89);
useEffect(() => {
if(!user.isAdmin) navigate("/")
}, [])
const incompleteEvents = [
{ title: "Événement A", tasks: "Préparation des flyers" },
{ title: "Événement B", tasks: "Réservation de la salle" },