Disallow access to /admin if user is not admin
This commit is contained in:
1 parent
c1a7db12e3
commit
2dd2cd2d4b
2 files changed
+12
-2
No files matched your search
@@ -14,6 +14,7 @@ export function AuthProvider({ children }) {
|
|||||||
const u = await getUser();
|
const u = await getUser();
|
||||||
setUser(u);
|
setUser(u);
|
||||||
setLoading(false);
|
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 { Doughnut } from "react-chartjs-2";
|
||||||
import { Chart, ArcElement } from "chart.js";
|
import { Chart, ArcElement } from "chart.js";
|
||||||
import styles from "./StatPage.module.css";
|
import styles from "./StatPage.module.css";
|
||||||
import Button from "./../../components/ui/button/button";
|
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
|
// Enregistrer les éléments nécessaires
|
||||||
Chart.register(ArcElement);
|
Chart.register(ArcElement);
|
||||||
|
|
||||||
function StatPage() {
|
function StatPage() {
|
||||||
|
|
||||||
|
const { user } = useContext(AuthContext);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [months, setMonths] = useState(3);
|
const [months, setMonths] = useState(3);
|
||||||
|
|
||||||
const [participationRate, setParticipationRate] = useState(89);
|
const [participationRate, setParticipationRate] = useState(89);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if(!user.isAdmin) navigate("/")
|
||||||
|
}, [])
|
||||||
|
|
||||||
const incompleteEvents = [
|
const incompleteEvents = [
|
||||||
{ title: "Événement A", tasks: "Préparation des flyers" },
|
{ title: "Événement A", tasks: "Préparation des flyers" },
|
||||||
{ title: "Événement B", tasks: "Réservation de la salle" },
|
{ title: "Événement B", tasks: "Réservation de la salle" },
|
||||||
|
|||||||
Reference in new issue
Block a user