To secure a Bolt.new + Next.js + Supabase stack, you need to: (1) use the correct Supabase client type for each Next.js context (browser vs server vs middleware), (2) add authentication verification to all Server Actions using auth.getUser(), (3) enable RLS on all Supabase tables, and (4) configure middleware to protect authenticated routes. This blueprint covers the unique security challenges of combining Next.js App Router with Supabase.
TL;DR
Next.js App Router requires different Supabase clients for different contexts. Bolt-generated code often mixes these up or skips auth verification in Server Actions. After export: verify correct client usage, add auth checks to all Server Actions, enable RLS on all tables, and configure middleware for protected routes.
Supabase Client Types
| Context | Client | Common Issue |
|---|---|---|
| Client Components | createBrowserClient | May use server client |
| Server Components | createServerClient | May skip cookie handling |
| Server Actions | createServerClient | Often missing auth check |
Part 1: Next.js Server Action Security
'use server'
import { createClient } from '@/lib/supabase/server'
export async function updateProfile(formData: FormData) {
const supabase = await createClient()
const { data: { user }, error } = await supabase.auth.getUser()
if (error || !user) {
throw new Error('Unauthorized')
}
await supabase.from('profiles').update({
name: formData.get('name')
}).eq('id', user.id) // Use verified user ID
return { success: true }
}
Critical: Always use auth.getUser() in Server Actions. Never trust user IDs from form data.
Security Checklist
Post-Export Checklist for Bolt + Next.js + Supabase
Correct Supabase client for each context
RLS enabled on all tables
Auth verification in all Server Actions
Middleware protects authenticated routes
User ID from auth.getUser(), not client
Service role key only in server code
Alternative Stacks to Consider
**Bolt.new + Supabase**
General Supabase security guide
**Bolt.new + Supabase + Vercel**
Complete deployment security
**Bolt.new + React + Firebase**
Firebase alternative stack
Why do I need different Supabase clients?
Next.js runs code in different environments. Each handles cookies and auth tokens differently. Using the wrong client causes auth state mismatches.
Building Next.js + Supabase with Bolt?
Scan for client misuse and auth vulnerabilities.
Start Free Scan