Skip to content

Storage: window.localstorage in createBrowserClient doesn't work #142

@tzvc

Description

@tzvc

Hey there,

I've been pulling my hair out because I want our app to authenticate users when loaded as iframe from a different source. Cookies seem to have a permission problem when trying to set them from a diff. domain so I thought i'd use localstorage for storing sessions instead:

Here's how I init my client on my NextJS 16 app:

"use client";
import { createBrowserClient } from "@supabase/ssr";
import { Database } from "../types/supabase";


export function getSupabaseClient() {
  return createBrowserClient<Database>(
    process.env.NEXT_PUBLIC_SUPABASE_URL as string,
    process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY as string,
    {
      auth: {
        autoRefreshToken: true,
        persistSession: true,
        storage: typeof window !== "undefined" ? window.localStorage : undefined,
        debug: true,
      },
    }
  );
}

The issue is that no matter what I use in the custom storage, the session is still always stored in cookies.

What am I missing here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions