Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[supabase/ssr] Calling createBrowserClient multiple times overriding cached client options #743

Open
2 tasks done
bombillazo opened this issue Feb 15, 2024 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@bombillazo
Copy link

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

We're using the createBrowserClient function to access the supabase client all across our frontend logic, where hooks are not available to get the client using the useSupabaseClient hook.

We noticed that if we do not pass the exact same options across the clients when we call this function, the existing client-cached options are overridden by other "instantiations." For example, we used the createBrowserClient function in our root app context, and in our auth helper function. In one, we defined common options to override and control, while in the other, we passed no options since we are leveraging the singleton pattern and expect the cached instance to keep the options.

The options we are changing specifically are:

{
  auth: {
    storage: {}
  },
  cookies: {}
}

This is causing issues where we are indeed using the same client but with reconfigured options since the function is not correctly merging the user-defined options with the default options. This is causing all sorts of havoc in the app due to inconsistent client behavior.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a browser client using the createBrowserClient and pass it specific client options (like custom get/set cookies)
  2. In another page or function, call the createBrowserClient with no options to get a second client
  3. Call the page/function where the second client is used; check the singleton client options, and they will not be the same.

Expected behavior

In theory, since we are using singleton = true by default and are not modifying it, we get the same instance. And we do, but the options have defaulted back since the second createBrowserClient call had no options, and it internally wrote over the original options.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: [e.g. 6.0.2]
  • Version of Node.js: [e.g. 10.10.0]

Additional context

Add any other context about the problem here.

@bombillazo bombillazo added the bug Something isn't working label Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant