diff --git a/src/app/page.tsx b/src/app/page.tsx index 3145025..0a6dc2c 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,4 +1,21 @@ -export default function HomePage() { +import { headers } from "next/headers"; +import { redirect } from "next/navigation"; + +import { auth } from "@/modules/auth/auth"; + +// ponytail: redirect authenticated users straight to their portal home instead +// of showing the public landing. The landing's "Zum Portal" button points at +// /anmelden, so without this redirect a logged-in user lands back on the login +// form — the post-login loop. /admin for admins, /redaktion/alben for editorials. +export default async function HomePage() { + const session = await auth.api.getSession({ headers: new Headers(await headers()) }); + if (session) { + // `role` is a custom column; Better Auth returns it (the drizzle adapter + // selects all columns) but doesn't type it. Mirror principal.ts's cast. + const role = (session.user as { role?: string }).role; + redirect(role === "ADMIN" ? "/admin" : "/redaktion/alben"); + } + return (
@@ -23,4 +40,4 @@ export default function HomePage() {
); -} +} \ No newline at end of file