refactor(app): move auth gating and metadata to server-first patterns
This commit is contained in:
74
app/page.tsx
74
app/page.tsx
@@ -1,65 +1,33 @@
|
||||
"use client";
|
||||
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { toast } from "@/lib/toast";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default function Home() {
|
||||
const t = useTranslations('toasts');
|
||||
const { data: session, isPending } = authClient.useSession();
|
||||
const router = useRouter();
|
||||
import { isAuthenticated } from "@/lib/auth-server";
|
||||
|
||||
if (isPending) {
|
||||
return (
|
||||
<main className="flex min-h-screen items-center justify-center">
|
||||
<p className="text-muted-foreground">Laden...</p>
|
||||
</main>
|
||||
);
|
||||
export default async function Home() {
|
||||
const authenticated = await isAuthenticated();
|
||||
|
||||
if (authenticated) {
|
||||
redirect("/dashboard");
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="flex min-h-screen flex-col items-center justify-center gap-6 p-4">
|
||||
<h1 className="text-4xl font-bold">🍋 LemonSpace</h1>
|
||||
|
||||
{session?.user ? (
|
||||
<div className="flex flex-col items-center gap-4">
|
||||
<p className="text-lg">
|
||||
Willkommen, <span className="font-semibold">{session.user.name}</span>
|
||||
</p>
|
||||
<Link
|
||||
href="/dashboard"
|
||||
className="rounded-lg bg-primary px-6 py-3 text-primary-foreground hover:bg-primary/90"
|
||||
>
|
||||
Zum Dashboard
|
||||
</Link>
|
||||
<button
|
||||
onClick={() => {
|
||||
toast.info(t('auth.signedOut'));
|
||||
void authClient.signOut().then(() => router.refresh());
|
||||
}}
|
||||
className="rounded-lg border border-border px-6 py-3 text-sm hover:bg-accent"
|
||||
>
|
||||
Abmelden
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex gap-4">
|
||||
<Link
|
||||
href="/auth/sign-in"
|
||||
className="rounded-lg bg-primary px-6 py-3 text-primary-foreground hover:bg-primary/90"
|
||||
>
|
||||
Anmelden
|
||||
</Link>
|
||||
<Link
|
||||
href="/auth/sign-up"
|
||||
className="rounded-lg border border-border px-6 py-3 hover:bg-accent"
|
||||
>
|
||||
Registrieren
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex gap-4">
|
||||
<Link
|
||||
href="/auth/sign-in"
|
||||
className="rounded-lg bg-primary px-6 py-3 text-primary-foreground hover:bg-primary/90"
|
||||
>
|
||||
Anmelden
|
||||
</Link>
|
||||
<Link
|
||||
href="/auth/sign-up"
|
||||
className="rounded-lg border border-border px-6 py-3 hover:bg-accent"
|
||||
>
|
||||
Registrieren
|
||||
</Link>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user