All resources
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

bash
pnpm add @supabase/ssr @supabase/supabase-js

Guard the route in middleware

ts
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

  1. Turn off public sign-ups in Supabase Auth
  2. Use getUser(), not getSession(), on the server
  3. Lock rows down with Row Level Security, not just the UI

Read the official guide for the full cookie setup.