Harden user management integration

This commit is contained in:
Julian Appel 2026-09-28 22:42:03 +02:00
parent 73579d1e79
commit 847f4e9493
18 changed files with 394 additions and 111 deletions

View file

@ -4,26 +4,27 @@ import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import { useEffect } from "react";
import { useAuth } from "../../frontend/components/AuthProvider";
const CONFIG_TABS = [
{ href: "/config/benutzer", label: "Benutzer" },
{ href: "/config/konto", label: "Konto" },
] as const;
import {
getConfigRedirect,
getConfigTabs,
} from "../../frontend/utils/config-access";
export default function ConfigLayout({ children }: { children: React.ReactNode }) {
const pathname = usePathname();
const router = useRouter();
const { status, isAdmin } = useAuth();
const tabs = getConfigTabs(isAdmin);
const redirectTarget = getConfigRedirect(pathname, isAdmin);
useEffect(() => {
// LoginGate already guarantees a signed-in user with a set password by
// the time this layout renders; only the role still needs checking.
if (status === "signed-in" && !isAdmin) {
router.replace("/");
}
}, [status, isAdmin, router]);
if (status !== "signed-in") return;
if (redirectTarget) router.replace(redirectTarget);
}, [status, redirectTarget, router]);
if (status !== "signed-in" || !isAdmin) {
if (
status !== "signed-in" ||
redirectTarget !== null
) {
return null;
}
@ -34,7 +35,7 @@ export default function ConfigLayout({ children }: { children: React.ReactNode }
</div>
<nav className="config-tabs">
{CONFIG_TABS.map((tab) => (
{tabs.map((tab) => (
<Link
key={tab.href}
href={tab.href}

View file

@ -1,5 +1,3 @@
import { redirect } from "next/navigation";
export default function ConfigPage() {
redirect("/config/benutzer");
return null;
}