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] Documentation for createServerClient & createBrowserClient #754

Open
biasedbit opened this issue Mar 28, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@biasedbit
Copy link

Improve documentation

Link

Describe the problem

Function names are pretty much self-explanatory but as I was reading through the implementation, both createServerClient and createBrowserClient have some conditional logic based on whether they're running on a browser, which I found to be surprising.

Describe the improvement

Add docs to clarify difference between functions and consequences of using them in the wrong env (e.g. what happens when createBrowserClient is used in server-side components and vice-versa).

Additionally:

  • If the functions aren't meant to be used outside their envs, log a warning or raise an error.
  • If it's okay to use either function in either env, explicitly state in docs.

Additional context

n/a


Happy to submit a PR with proposed changes once I understand the crossed-env usage caveats (mainly createBrowserClient on server-side, since createServerClient with cookies() on client-side will naturally fail due to "(...) importing a component that needs next/headers (...)".

@biasedbit biasedbit added the documentation Improvements or additions to documentation label Mar 28, 2024
@elie222
Copy link

elie222 commented Jun 5, 2024

I'm also wondering if there are any issues with initialising just once:

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

export const createClient = (): any =>
  createBrowserClient(
    env.NEXT_PUBLIC_SUPABASE_URL,
    env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
  );

export const browserClient = createClient();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants