"use client"; import { useEffect, useState } from "react"; import { SignOutButton } from "../../components/sign-out-button"; import { SiteHeader } from "../../components/site-header"; import { authClient } from "../../lib/auth-client"; type SessionState = | { status: "loading" } | { status: "unauthorized" } | { status: "ready"; session: { user: { createdAt: Date | string; email: string; name: string; }; session: { expiresAt: Date | string; id: string; }; }; }; export default function DashboardPage() { const [sessionState, setSessionState] = useState({ status: "loading" }); useEffect(() => { let cancelled = false; authClient .getSession() .then((response) => { if (cancelled) { return; } if (response.error || !response.data?.user) { setSessionState({ status: "unauthorized" }); window.location.replace("/sign-in"); return; } setSessionState({ status: "ready", session: response.data, }); }) .catch(() => { if (!cancelled) { setSessionState({ status: "unauthorized" }); window.location.replace("/sign-in"); } }); return () => { cancelled = true; }; }, []); if (sessionState.status === "loading") { return (
Verifying protected session
); } if (sessionState.status === "unauthorized") { return (
Session unavailable

Returning you to the sign-in page…

); } const { session } = sessionState; const createdAt = new Date(session.user.createdAt).toLocaleDateString("en", { day: "numeric", month: "short", year: "numeric", }); const expiresAt = new Date(session.session.expiresAt).toLocaleString("en", { day: "numeric", hour: "2-digit", minute: "2-digit", month: "short", }); return (
PROTECTED / MIDDLEWARE VERIFIED

Welcome back, {session.user.name}.

Farm route middleware verified your session before this dashboard loaded.

Account
Name
{session.user.name}
Email
{session.user.email}
Created
{createdAt}
Current session httpOnly cookie
Session ID
{session.session.id}
Expires
{expiresAt}
Storage
Neon Postgres
NEXT / MAKE IT YOURS

The account boundary is ready for product work.

01

Set the production auth URL, secret, and pooled database URL in your host.

02

Add GitHub or Google inside src/lib/auth.ts when you need OAuth.

03

Build your first protected feature beside this dashboard route.

); }