Skip to content

createBrowserClient with cookies: { encode: "tokens-only" } throws outside a browser runtime (Next.js pre-rendering) #293

Closed

Description

@PhuocOng

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

createBrowserClient runs fine in a non-browser runtime (for example during Next.js pre-rendering, where window is undefined) when the cookies option is omitted: it falls back to an empty getAll and a lazily throwing setAll. As soon as cookies: { encode: "tokens-only" } is passed, the same call throws, even though encode only changes how the session is written to cookies:

  • cookies: { encode: "tokens-only" } (no accessors) throws @supabase/ssr: createBrowserClient requires configuring getAll and setAll cookie methods (deprecated: alternatively use get, set and remove).
  • cookies: { encode: "tokens-only", getAll, setAll } throws ReferenceError: window is not defined, coming from the userStorage: window.localStorage default that tokens-only enables.

So opting into tokens-only currently makes a client component that pre-renders on the server crash, while the exact same component without encode works.

To Reproduce

Minimal script against the published package, run with Node (no window, same as a pre-rendering pass):

// repro.mjs
import { createBrowserClient } from "@supabase/ssr";

const cases = {
  "no cookies option": undefined,
  "cookies: { encode: 'tokens-only' }": { encode: "tokens-only" },
  "cookies: { encode, getAll, setAll }": { encode: "tokens-only", getAll: () => [], setAll: () => {} },
};

for (const [label, cookies] of Object.entries(cases)) {
  try {
    createBrowserClient("https://example.supabase.co", "anon-key", { isSingleton: false, ...(cookies && { cookies }) });
    console.log("OK   ", label);
  } catch (e) {
    console.log("THROW", label, "\n     ", e.constructor.name + ":", e.message);
  }
}
$ npm i @supabase/ssr@latest && node repro.mjs
OK    no cookies option
THROW cookies: { encode: 'tokens-only' }
      Error: @supabase/ssr: createBrowserClient requires configuring getAll and setAll cookie methods (deprecated: alternatively use get, set and remove).
THROW cookies: { encode, getAll, setAll }
      ReferenceError: window is not defined

Expected behavior

A cookies object that only sets encode should behave like omitting cookies in every runtime, as the comment added in #213 describes ("same as when cookies isn't provided at all"): document.cookie in a browser, and the existing non-browser fallback otherwise. With tokens-only, userStorage should fall back to an in-memory adapter outside a browser, the way createServerClient already does with memoryLocalStorageAdapter().

Screenshots

Image

System information

  • OS: Windows 11
  • Version of @supabase/ssr: 0.12.6
  • Version of Node.js: 24.14.0

Additional context

Looks like the encode-only fallback introduced in #213 only mirrors the browser branch (!isServerClient && isBrowser()), so the non-browser branch that runs when cookies is omitted is never reached. Happy to open a PR.

Activity

  1. added
    bug
    on Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions