Disallow access to /admin if user is not admin
This commit is contained in:
@@ -14,6 +14,7 @@ export function AuthProvider({ children }) {
|
||||
const u = await getUser();
|
||||
setUser(u);
|
||||
setLoading(false);
|
||||
console.log(u);
|
||||
})();
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -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" },
|
||||
|
||||
Reference in New Issue
Block a user