ESC
NextStarterAI logo
Menu
On this page

Tutorials > Private Page

🔐 Once the user is authenticated, it's time to craft some exclusive routes! 🚀 Build a personalized user dashboard, an awesome account page, and more! 🌟


Protected API

🔒 Want to make protected API calls? 🚀 Follow the Protected API tutorial to unlock the secrets! 🌟

🔒 /dashboard's layout.ts keeps pages private. Unauthenticated? Swift redirect to login! 🚀 (Check config.ts for auth.)


Check out this sneak peek! A simple user dashboard revealing private user data in a server component. 🌟


/app/dashboard/page.tsx
1 2 import { cookies } from "next/headers"; 3 import { createServerComponentClient } from "@supabase/auth-helpers-nextjs"; 4 5 // Define a dynamic variable for forced dynamic rendering 6 export const dynamic = "force-dynamic"; 7 8 // This page is marked private and relies on the layout.js component to enforce authentication. 9 // Being a server component allows pre-rendering data, such as fetching the user's profile. 10 export default async function Dashboard() { 11 // Create a Supabase client for server components with cookies support 12 const supabase = createServerComponentClient({ cookies }); 13 14 // Fetch todos data from the Supabase database 15 const { data } = await supabase.from("todos").select(); 16 17 // Display private content in the main section 18 return ( 19 <main className="min-h-screen p-8 pb-24"> 20 <section className="max-w-xl mx-auto space-y-8"> 21 {/* Greet users with a bold title */} 22 <h1 className="text-3xl md:text-4xl font-extrabold">Welcome to the Private Page</h1> 23 24 {/* Show the fetched data only when an SQL table named todos has at least one row */} 25 <pre>{JSON.stringify(data, null, 2)}</pre> 26 </section> 27 </main> 28 ); 29 } 30