Superuser
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Routes, Route } from "react-router-dom";
|
||||
import { useEffect, useState, useCallback } from "react";
|
||||
import { Routes, Route, useLocation, useNavigate } from "react-router-dom";
|
||||
import { Cog6ToothIcon } from "@heroicons/react/24/solid";
|
||||
import { IconButton } from "@material-tailwind/react";
|
||||
import {
|
||||
@@ -13,6 +14,58 @@ import { useMaterialTailwindController, setOpenConfigurator } from "@/components
|
||||
export function Dashboard() {
|
||||
const [controller, dispatch] = useMaterialTailwindController();
|
||||
const { sidenavType } = controller;
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const [superuserRequired, setSuperuserRequired] = useState(false);
|
||||
const [statusChecked, setStatusChecked] = useState(false);
|
||||
|
||||
const checkSuperuserStatus = useCallback(async () => {
|
||||
setStatusChecked(false);
|
||||
try {
|
||||
const response = await fetch("/api/auth/superuser/status");
|
||||
if (!response.ok) {
|
||||
throw new Error("STATUS_REQUEST_FAILED");
|
||||
}
|
||||
const data = await response.json();
|
||||
setSuperuserRequired(!data.exists);
|
||||
} catch (error) {
|
||||
console.error("⚠️ [Superuser] Statusprüfung fehlgeschlagen:", error);
|
||||
setSuperuserRequired(true);
|
||||
} finally {
|
||||
setStatusChecked(true);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
checkSuperuserStatus();
|
||||
}, [checkSuperuserStatus]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!statusChecked) return;
|
||||
if (superuserRequired) {
|
||||
if (location.pathname !== "/auth/regsuperuser") {
|
||||
navigate("/auth/regsuperuser", { replace: true });
|
||||
}
|
||||
} else if (location.pathname === "/auth/regsuperuser") {
|
||||
navigate("/dashboard/stacks", { replace: true });
|
||||
}
|
||||
}, [superuserRequired, statusChecked, location.pathname, navigate]);
|
||||
|
||||
if (!statusChecked) {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-blue-gray-50/50">
|
||||
<span className="text-blue-gray-500">Lade Systemstatus ...</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (superuserRequired) {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-blue-gray-50/50">
|
||||
<span className="text-blue-gray-500">Superuser-Einrichtung erforderlich ...</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-blue-gray-50/50">
|
||||
|
||||
Reference in New Issue
Block a user