Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

Supabase SSR

Supabase client library optimized for server-side rendering frameworks.

SDKs for hosted servicesNPM

GitHubWebsite

1. License

License from npm.

github.com/supabase/ssr

From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error

What Supabase SSR does

Supabase SSR always keeps the Supabase auth session in cookies, which the README calls "the entire point of the package", so a server-rendered request reads the same session the browser wrote.

Supabase SSR popularity

61 / 100
Gid Score, #977 overall
14.6M
downloads a week, npm
217
GitHub stars
286
agent projects use it
Supabase SSR: downloads per weeknpm, @supabase/ssr 14,575,109
Supabase SSR: GitHub starssupabase/ssr 217

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How Supabase SSR is used

  • Supabase SSR is a dependency in 286 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (5.9% of the 4,867 JavaScript/TypeScript ones), #2 of 287 in sdks for hosted services.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 564; those are left out of every share on this page.
  • Projects that use it most often also use Supabase JS (97.9%), Next.js (93.7%), Lucide React (82.9%).
  • It is more common in projects set up for Roo Code (6.3%) than for OpenCode (2.6%).

By coding agent

147 projects, 4.5%
135 projects, 5.5%
133 projects, 4.4%
20 projects, 4.2%
18 projects, 3.8%
16 projects, 5.7%
9 projects, 2.6%
7 projects, 6.3%

Often used with

In 97.9% of its projects
In 93.7% of its projects
In 82.9% of its projects
In 75.2% of its projects
In 75.5% of its projects
In 96.5% of its projects
In 96.5% of its projects
In 69.6% of its projects

Supabase SSR in practice

Strengths

Server and browser read one session

The session lives in cookies, so a server-rendered page sees the same logged-in user as the browser. The README says this is why the package exists.

One package instead of four auth-helpers

The maintainers write that the Next.js, React, Remix and SvelteKit auth-helpers are deprecated and "consolidated into <code>@supabase/ssr</code> for better maintenance and consistency."

Not tied to one framework

The README's overview describes the package as "a framework-agnostic way" to use the Supabase JavaScript library in SSR frameworks.

Full React Router middleware recipe

The README gives complete middleware code. It builds the server client with <code>parseCookieHeader</code>, calls <code>getClaims()</code> "before any route code runs", and appends each queued cookie as <code>Set-Cookie</code> with <code>serializeCookieHeader</code>.

Watch out for

auth.storage is ignored

The README says passing <code>auth.storage</code> has no effect, and a one-time console warning is logged. The exception is <code>auth.userStorage</code>, which is still respected when <code>cookies.encode</code> is set to <code>"tokens-only"</code>.

Wrong choice for browser-only apps

If the server never needs the session, the README points to <code>createClient</code> from <code>@supabase/supabase-js</code> with your own <code>storage</code>. It says there is "no reason" to use <code>@supabase/ssr</code> in that case.

Racing refreshes can return a null session

Supabase refresh tokens are single-use. If two requests arrive at the same moment with the same expired cookie, such as two tabs opening together, the second refresh fails and that request gets <code>session: null</code>. The README says middleware mitigates this "for the common case". Parallel client <code>fetch()</code> calls still need to handle <code>null</code> sessions and retry or re-authenticate.

React Router middleware: refresh the session before any route code runs

export const supabaseMiddleware: MiddlewareFunction<Response> = async (
  { request, context }, next,
) => {
  const pendingCookies: PendingCookie[] = [];
  const pendingHeaders: Record<string, string> = {};
  const supabase = createServerClient(
    process.env.SUPABASE_URL!,
    process.env.SUPABASE_PUBLISHABLE_KEY!,
    {
      cookies: {
        getAll() {
          return parseCookieHeader(request.headers.get("Cookie") ?? "");
        },
        setAll(cookiesToSet, headers) {
          pendingCookies.push(...cookiesToSet);
          Object.assign(pendingHeaders, headers);
        },
      },
    },
  );
  // Trigger lazy session init / refresh before any route code runs.
  await supabase.auth.getClaims();
  context.set(supabaseContext, supabase);
  const response = await next();
  for (const { name, value, options } of pendingCookies) {
    response.headers.append(
      "Set-Cookie",
      serializeCookieHeader(name, value, options),
    );
  }
  for (const [key, value] of Object.entries(pendingHeaders)) {
    response.headers.set(key, value);
  }
  return response;
};

More about Supabase SSR

Funding
  • GitHub Sponsors: https://github.com/supabase
  • 18 GitHub sponsors

See all

Packages around it
  • @supabase/supabase-js: Core Supabase client
  • next: React framework
  • lucide-react: Icon set
  • clsx: Class name joiner
  • tailwind-merge: Tailwind class merging
  • class-variance-authority: Component variants
More in SDKs for hosted services

Alternatives

Supabase SSR This page

MITGid 6114.6M/wk

Compare Supabase SSR with another tool

Get started

Install it.

npm install @supabase/ssr

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## Supabase SSR
- Use `@supabase/ssr` only when server code needs the session. For browser-only session handling, use `createClient` from `@supabase/supabase-js` with your own `storage`.
- Do not add `@supabase/auth-helpers-nextjs`, `-react`, `-remix` or `-sveltekit`. The README lists them as deprecated; depend on `@supabase/ssr` directly.
- Do not pass `auth.storage` to `createBrowserClient` or `createServerClient`. It has no effect and logs a warning. `auth.userStorage` is respected only when `cookies.encode` is `"tokens-only"`.
- Follow the README's middleware example. Give `createServerClient` a `cookies.getAll` that parses the request's `Cookie` header with `parseCookieHeader`. Add a `cookies.setAll` that queues cookies and headers. Append each queued cookie with `serializeCookieHeader` as `Set-Cookie` and set the queued headers on the response.
- Refresh the session once per request in middleware with `await supabase.auth.getClaims()` before loaders and actions run.
- When parallel client requests may race to refresh the same expired token, handle `session: null` and retry or re-authenticate.
- For choosing between `getSession()`, `getUser()` and `getClaims()`, follow the official guides at https://supabase.com/docs/guides/auth/server-side.