Next.js + Supabase
Build a full-stack Next.js app with Supabase Auth (email + social login), a PostgreSQL database, and proper SSR support using the @supabase/ssr package.
Create Next.js Project
Scaffold a new Next.js app with TypeScript and the App Router.
npx create-next-app@latest my-app --typescript --tailwind --app --src-dirInstall Supabase Packages
Install @supabase/supabase-js (core client) and @supabase/ssr (the SSR helper that handles cookies for Server Components and Route Handlers).
npm install @supabase/supabase-js @supabase/ssrCreate a Supabase Project and Get Keys
Go to supabase.com, create a project, then open Project Settings → API. Copy the Project URL and the anon public key.
Create the Browser Client Utility
This client is used in Client Components. createBrowserClient reads cookies automatically to hydrate the auth session in the browser.
Create the Server Client Utility
This client is used in Server Components, Route Handlers, and Server Actions. It uses Next.js cookies() to read and write session cookies server-side.
Add the Auth Middleware
Create src/middleware.ts. The middleware refreshes the Supabase session on every request so Server Components always see up-to-date auth state.
Create Auth Server Actions
Server Actions are the recommended way to trigger auth flows in the App Router — no API route needed.
Create the Login Page
A simple login form that calls the login Server Action on submit.
Build a Protected Dashboard
Use the server client in a Server Component to get the current user. The middleware redirects unauthenticated requests before this runs.
Query the Database
Supabase's auto-generated client lets you query your PostgreSQL tables directly — no raw SQL needed for common operations.
Start the Development Server
npm run devFound this guide helpful? Check out more tools and guides.
Browse All GuidesPrerequisites
- Node.js 18+
- Supabase account (supabase.com — free tier available)