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

fix: allow use of createBrowserClient without window present #20

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,17 @@ export function createStorageFromOptions(
"@supabase/ssr: createServerClient must be initialized with cookie options that specify getAll and setAll functions (deprecated, not recommended: alternatively use get, set and remove)",
);
} else {
throw new Error(
"@supabase/ssr: createBrowserClient in non-browser runtimes must be initialized with cookie options that specify getAll and setAll functions (deprecated: alternatively use get, set and remove)",
);
// getting cookies when there's no window but we're in browser mode can be OK, because the developer probably is not using auth functions
getAll = () => {
hf marked this conversation as resolved.
Show resolved Hide resolved
return [];
};

// this is NOT OK because the developer is using auth functions that require setting some state, so that must error out
setAll = () => {
throw new Error(
"@supabase/ssr: createBrowserClient in non-browser runtimes (including Next.js pre-rendering mode) was not initialized cookie options that specify getAll and setAll functions (deprecated: alternatively use get, set and remove), but they were needed",
);
};
}

if (!isServerClient) {
Expand Down