Why Next.js + Supabase?
Next.js and Supabase work perfectly together:- Server Components for secure data fetching
- Server Actions for mutations
- Middleware for auth protection
- Edge Runtime support
- Type safety with TypeScript
Quick Start
Create Supabase Clients
Create Create Create
lib/supabase/client.ts for Client Components:lib/supabase/server.ts for Server Components:lib/supabase/middleware.ts for Middleware:Usage Patterns
Server Components (Recommended)
Fetch data securely in Server Components:Client Components
Use Client Components for interactivity:Server Actions
Handle mutations with Server Actions:Route Handlers
Create API routes:Authentication
Sign Up/Sign In
Createapp/login/actions.ts:
Protected Routes
Protect pages in Server Components:OAuth Providers
Sign in with OAuth:app/auth/callback/route.ts:
Real-time Subscriptions
Subscribe to changes in Client Components:Type Safety
Generate types from your database:Best Practices
Use Server Components
Fetch data in Server Components when possible for better security and performance.
Server Actions for Mutations
Use Server Actions instead of Route Handlers for form submissions and mutations.
Client Components for Interactivity
Use Client Components only when you need hooks, event handlers, or browser APIs.
Middleware for Auth
Use middleware to refresh auth sessions automatically.
Type Generation
Generate TypeScript types from your database schema.
Next Steps
Build a Todo App
Follow our step-by-step tutorial
User Management
Add user profiles and avatars
File Uploads
Integrate Supabase Storage
Realtime Chat
Build a chat application
