fix(home): redirect authenticated users to their portal home

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 <noreply@anthropic.com>
This commit is contained in:
Leon TonhäuserandClaude committed 2026-08-11 00:19:52 +02:00
1 parent 3316365b73
commit cc2079db77
1 file changed
+19 -2
+19 -2
View File
@@ -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 ( return (
<main className="landing"> <main className="landing">
<header className="masthead"> <header className="masthead">
@@ -23,4 +40,4 @@ export default function HomePage() {
</footer> </footer>
</main> </main>
); );
} }