From cc2079db77b44a97412fc74c515708eaf92faae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Tonh=C3=A4user?= Date: Tue, 11 Aug 2026 00:19:52 +0200 Subject: [PATCH] fix(home): redirect authenticated users to their portal home MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The root page was a static public landing that always shows a 'Zum Portal' button pointing at /anmelden, and /anmelden never redirects authenticated users. After login the callbackURL '/' landed on this static page, so the user saw the login form again — the post-login loop. Make / an async server component that reads the session and redirects to /admin (admin) or /redaktion/alben (editorial); unauthenticated users still see the landing. Co-Authored-By: Claude --- src/app/page.tsx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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