Supabase is now compatible with Next.js 14
Supabase works across every Next.js 14 rendering context, including App Router Client and Server Components, Route Handlers, Server Actions and Middleware, plus the Pages Router data-fetching functions. Now that Server Actions are stable, auth and mutations can run entirely server-side next to the Server Components that fetch data. supabase-js stores sessions in localStorage by default, which doesn't exist on the server, so it has to be configured with cookie-based storage on both server and browser. The new @supabase/ssr package and a create-next-app starter template (`-e with-supabase`) wrap that boilerplate.
Related posts
- Introducing @supabase/server
Supabase mediumAdept@supabase/server, now in public beta, replaces the repeated setup code found across 25,000 analyzed Edge Functions: client creation, JWT verification, claims parsing, CORS and auth wiring. A withSupabase wrapper (or createSupabaseContext for custom error handling) takes a declarative auth mode such as 'user', 'none', 'secret', 'publishable' or a combination. It rejects unauthorized requests before the handler runs and supplies a context with a user-scoped RLS client, a service-role admin client and verified claims. It handles the new asymmetric JWT signing keys and API keys internally, so migrating needs no jose or JWKS setup. It returns a standard Request-to-Response handler that runs on Edge Functions, Vercel, Cloudflare Workers, Bun and Hono, and exposes lower-level primitives for per-route auth.
- Fetching and caching Supabase data in Next.js 13 Server Components
Supabase mediumAdeptNext.js 13's app directory lets async Server Components query Supabase directly, with caching controlled by an exported `revalidate` value instead of separate getStaticProps/getServerSideProps functions. The walkthrough covers four strategies: static generation with `generateStaticParams`, incremental revalidation (e.g. `revalidate = 60`), fully dynamic fetching (`revalidate = 0`), and client components using `use client`. It closes with a hybrid pattern that loads initial data in a Server Component and passes it to a Client Component subscribed to Supabase Realtime Postgres changes, which separates data fetching from caching policy.
- supabase-js v2
Supabase mediumAdeptsupabase-js v2 brings incremental quality-of-life changes over v1. Types are now generated from the database via the CLI and set once on the client. signIn() is split into signInWithPassword() and signInWithOtp(), server-side auth moves to auth.admin, and the auth library is now async to fix a multi-tab token refresh race condition that logged users out. insert/update/upsert no longer return data unless select() is appended, which avoids surprise failures under Row Level Security. Constructor config is scoped per sub-library, each sub-library gets typed errors, Edge Function invocations auto-detect content type, and a new channel() API replaces from().on() for realtime and Postgres change subscriptions. v1 gets security and maintenance patches for three months.
- Using React Query with Next.js App Router and Supabase Cache Helpers
Supabase mediumAdeptReact Query can be paired with supabase-js in a Next.js App Router app by wrapping the root layout in a client-side QueryClientProvider and creating typed browser and server Supabase clients via @supabase/ssr. Supabase Cache Helpers generate query keys automatically from supabase-js queries, so one reusable query function can be prefetched in a server component and hydrated through HydrationBoundary, letting the client render without a loading state, or fetched purely client-side. The recommendation is to reach for React Query with Server Components only when migrating an existing React Query app or when it covers needs the framework doesn't; otherwise start with the framework's own data fetching.
- Supabase Middleware: composable, reusable middleware for Web Fetch handlers
Supabase mediumAdept`@supabase/middleware` is an MIT-licensed, type-safe middleware engine for Web Fetch handlers. Per-request logic such as CORS, JWT claim verification, feature flags, RLS-scoped Supabase/Postgres clients and MCP OAuth discovery is composed as an ordered pipeline that each adds a typed key to a shared ctx, can short-circuit with a Response, or modify the response on the way out. The pipeline is a plain fetch handler, so it runs on Edge Functions, Vercel, Cloudflare Workers, Deno, Bun and Node 22+. Copy-in bridge files reuse the same entries in Hono, H3, Elysia, NestJS and TanStack Start. Custom middleware is written with `defineMiddleware`, whose type parameters make duplicate keys or misordered dependencies fail to compile (TypeScript 5.4+). The pg-based clients don't work on Workers because they need TCP sockets.