feat: cron done, admin unfinished

This commit is contained in:
2025-05-31 06:02:48 -04:00
parent b8ce9ded76
commit a91469257b
8 changed files with 81 additions and 11 deletions
+3
View File
@@ -0,0 +1,3 @@
export function AdminPage() {
return <div>{"adminpage"}</div>;
}
+26
View File
@@ -0,0 +1,26 @@
import { useEffect, useState, type JSX } from "react";
import { Navigate, useLocation } from "react-router-dom";
import { getCurrentUser } from "../helper/auth";
export const RequireAdmin = ({ children }: { children: JSX.Element }) => {
const [isAdmin, setIsAdmin] = useState<boolean | null>(null);
const [loading, setLoading] = useState(true);
const location = useLocation();
useEffect(() => {
const checkAdmin = async () => {
const user = await getCurrentUser();
setIsAdmin(user.isAdmin);
setLoading(false);
};
checkAdmin();
}, []);
if (loading) return <div>Checking permissions...</div>;
if (!isAdmin) {
return <Navigate to="/unauthorized" state={{ from: location }} replace />;
}
return children;
};
+10
View File
@@ -0,0 +1,10 @@
const Unauthorized = () => {
return (
<div className="p-4 text-red-600">
<h1 className="text-xl font-bold">403 - Unauthorized</h1>
<p>You do not have permission to view this page.</p>
</div>
);
};
export default Unauthorized;