Skip to content
Open
Show file tree
Hide file tree
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
43 changes: 7 additions & 36 deletions src/createBrowserClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import {
import { VERSION } from "./version";
import { isBrowser } from "./utils";

import type {
CookieMethodsBrowser,
CookieMethodsBrowserDeprecated,
CookieOptionsWithName,
} from "./types";
import type { CookieMethodsBrowser, CookieOptionsWithName } from "./types";

import { createStorageFromOptions } from "./cookies";

Expand Down Expand Up @@ -47,36 +43,11 @@ export function createBrowserClient<
supabaseUrl: string,
supabaseKey: string,
options?: SupabaseClientOptions<SchemaName> & {
cookies?: CookieMethodsBrowser;
cookieOptions?: CookieOptionsWithName;
cookieEncoding?: "raw" | "base64url";
isSingleton?: boolean;
},
): SupabaseClient<Database, SchemaName>;

/**
* @deprecated Please specify `getAll` and `setAll` cookie methods instead of
* the `get`, `set` and `remove`. These will not be supported in the next major
* version.
*/
export function createBrowserClient<
Database = any,
SchemaName extends string &
keyof Omit<Database, "__InternalSupabase"> = "public" extends keyof Omit<
Database,
"__InternalSupabase"
>
? "public"
: string & keyof Omit<Database, "__InternalSupabase">,
>(
supabaseUrl: string,
supabaseKey: string,
options?: SupabaseClientOptions<SchemaName> & {
cookies: CookieMethodsBrowserDeprecated;
cookies: CookieMethodsBrowser;
cookieOptions?: CookieOptionsWithName;
cookieEncoding?: "raw" | "base64url";
isSingleton?: boolean;
},
}
): SupabaseClient<Database, SchemaName>;

export function createBrowserClient<
Expand All @@ -92,11 +63,11 @@ export function createBrowserClient<
supabaseUrl: string,
supabaseKey: string,
options?: SupabaseClientOptions<SchemaName> & {
cookies?: CookieMethodsBrowser | CookieMethodsBrowserDeprecated;
cookies?: CookieMethodsBrowser;
cookieOptions?: CookieOptionsWithName;
cookieEncoding?: "raw" | "base64url";
isSingleton?: boolean;
},
}
): SupabaseClient<Database, SchemaName> {
// singleton client is created only if isSingleton is set to true, or if isSingleton is not defined and we detect a browser
const shouldUseSingleton =
Expand All @@ -109,7 +80,7 @@ export function createBrowserClient<

if (!supabaseUrl || !supabaseKey) {
throw new Error(
`@supabase/ssr: Your project's URL and API key are required to create a Supabase client!\n\nCheck your Supabase project's API settings to find these values\n\nhttps://supabase.com/dashboard/project/_/settings/api`,
`@supabase/ssr: Your project's URL and API key are required to create a Supabase client!\n\nCheck your Supabase project's API settings to find these values\n\nhttps://supabase.com/dashboard/project/_/settings/api`
);
}

Expand All @@ -118,7 +89,7 @@ export function createBrowserClient<
...options,
cookieEncoding: options?.cookieEncoding ?? "base64url",
},
false,
false
);

const client = createClient<Database, SchemaName>(supabaseUrl, supabaseKey, {
Expand Down
27 changes: 1 addition & 26 deletions src/createServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,9 @@ import { createStorageFromOptions, applyServerStorage } from "./cookies";
import type {
CookieOptionsWithName,
CookieMethodsServer,
CookieMethodsServerDeprecated,
} from "./types";
import { memoryLocalStorageAdapter } from "./utils/helpers";

/**
* @deprecated Please specify `getAll` and `setAll` cookie methods instead of
* the `get`, `set` and `remove`. These will not be supported in the next major
* version.
*/
export function createServerClient<
Database = any,
SchemaName extends string &
keyof Omit<Database, "__InternalSupabase"> = "public" extends keyof Omit<
Database,
"__InternalSupabase"
>
? "public"
: string & keyof Omit<Database, "__InternalSupabase">,
>(
supabaseUrl: string,
supabaseKey: string,
options: SupabaseClientOptions<SchemaName> & {
cookieOptions?: CookieOptionsWithName;
cookies: CookieMethodsServerDeprecated;
cookieEncoding?: "raw" | "base64url";
},
): SupabaseClient<Database, SchemaName>;

/**
* Creates a Supabase Client for use on the server-side of a server-side
* rendering (SSR) framework.
Expand Down Expand Up @@ -132,7 +107,7 @@ export function createServerClient<
supabaseKey: string,
options: SupabaseClientOptions<SchemaName> & {
cookieOptions?: CookieOptionsWithName;
cookies: CookieMethodsServer | CookieMethodsServerDeprecated;
cookies: CookieMethodsServer;
cookieEncoding?: "raw" | "base64url";
},
): SupabaseClient<Database, SchemaName> {
Expand Down
37 changes: 28 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ export type SetAllCookies = (
cookies: { name: string; value: string; options: CookieOptions }[],
) => Promise<void> | void;

export type CookieMethodsBrowserDeprecated = {
get: GetCookie;
set: SetCookie;
remove: RemoveCookie;
};

export type CookieMethodsBrowser = {
/**
Expand All @@ -44,11 +39,20 @@ export type CookieMethodsBrowser = {

getAll: GetAllCookies;
setAll: SetAllCookies;
};

export type CookieMethodsServerDeprecated = {
get: GetCookie;
/**
* @deprecated Please specify `getAll` methods instead of `get`. This will
* not be supported in the next major version.
*/
get?: GetCookie;
/**
* @deprecated Please specify `setAll` methods instead of `set`. This will
* not be supported in the next major version.
*/
set?: SetCookie;
/**
* @deprecated Please specify `setAll` methods instead of `remove`. This will
* not be supported in the next major version.
*/
remove?: RemoveCookie;
};

Expand All @@ -64,4 +68,19 @@ export type CookieMethodsServer = {

getAll: GetAllCookies;
setAll?: SetAllCookies;
/**
* @deprecated Please specify `getAll` methods instead of `get`. This will
* not be supported in the next major version.
*/
get?: GetCookie;
/**
* @deprecated Please specify `setAll` methods instead of `set`. This will
* not be supported in the next major version.
*/
set?: SetCookie;
/**
* @deprecated Please specify `setAll` methods instead of `remove`. This will
* not be supported in the next major version.
*/
remove?: RemoveCookie;
};
Loading