Next.jsSupabaseAuth
Supabase Auth on Next.js 16 at the Edge
Email + password sign-in for a Next.js app on Cloudflare Pages, with middleware that refreshes the session and guards an admin area.
Monday, October 12, 2026 · 1 min read · by Cyrus Bitangcol
Supabase's SSR helpers keep the session in cookies, which is exactly what an Edge runtime needs: no Node APIs, just Request and Response.
Install
pnpm add @supabase/ssr @supabase/supabase-jsGuard the route in middleware
export async function middleware(req: NextRequest) {
const supabase = createServerClient(URL, KEY, { cookies: { /* getAll / setAll */ } });
const { data: { user } } = await supabase.auth.getUser();
if (!user) return NextResponse.redirect(new URL("/login", req.url));
} On Cloudflare Pages keep the file named middleware.ts: Next 16's proxy.ts only runs on Node.js.
Before you ship
- Turn off public sign-ups in Supabase Auth
- Use
getUser(), notgetSession(), on the server - Lock rows down with Row Level Security, not just the UI
Read the official guide for the full cookie setup.
