/** * Server Component with Clerk Auth * * Demonstrates using auth() and currentUser() in Server Components * * CRITICAL (v6): auth() is now async - must use await */ import { auth, currentUser } from '@clerk/nextjs/server' import { redirect } from 'next/navigation' export default async function DashboardPage() { /** * Option 1: Lightweight auth check * * Use auth() when you only need userId/sessionId * This is faster than currentUser() */ const { userId, sessionId } = await auth() // Redirect if not authenticated (shouldn't happen if middleware configured) if (!userId) { redirect('/sign-in') } /** * Option 2: Full user object * * Use currentUser() when you need full user data * Heavier than auth(), so use sparingly */ const user = await currentUser() return (
User ID: {userId}
Session ID: {sessionId}
Email:{' '} {user?.primaryEmailAddress?.emailAddress}
Name: {user?.firstName} {user?.lastName}
{/* Access public metadata */} {user?.publicMetadata && (