Skip to content

createServerClient and createBrowserClient disagree on storage key when both cookieOptions.name and auth.storageKey are set #302

Open

Description

@dasjideepak

Bug

With the same options, createBrowserClient uses cookieOptions.name as the storage key, while createServerClient uses auth.storageKey. The browser writes the session to one cookie and the server reads another, so the server sees no session. This only happens when both options are set to different values.

In createBrowserClient.ts, ...options?.auth is spread first and cookieOptions.name overrides it. In createServerClient.ts the order is reversed.

Reproduction

@supabase/ssr@0.12.7, @supabase/supabase-js@2.117.2, Node 24.

import { createBrowserClient, createServerClient } from "@supabase/ssr";

const cookies = { getAll: () => [], setAll: () => {} };
const opts = {
  cookies,
  cookieOptions: { name: "from-cookie-options" },
  auth: { storageKey: "from-auth" },
};

const b = createBrowserClient("https://x.supabase.co", "key", { ...opts, isSingleton: false });
const s = createServerClient("https://x.supabase.co", "key", opts);

console.log(b.auth.storageKey); // from-cookie-options
console.log(s.auth.storageKey); // from-auth

Expected

Both clients use the same key, so a session written by the browser client is read by the server client.

Actual

They use different keys. getSession() on the server returns null for a signed-in user.

I have a fix with a test (server uses the same precedence as the browser: cookieOptions.name wins) and can open a PR.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions