@supabase/ssr
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -11,15 +11,10 @@ import * as _supabase_supabase_js from '@supabase/supabase-js'; | ||
} & CookieOptions; | ||
type ServerCookieMethods = { | ||
get: (key: string) => Promise<string | null | undefined> | string | null | undefined; | ||
set: (key: string, value: string, options?: CookieOptions) => Promise<void> | void; | ||
remove: (key: string, options?: CookieOptions) => Promise<void> | void; | ||
}; | ||
type BrowserCookieMethods = { | ||
type CookieMethods = { | ||
get?: (key: string) => Promise<string | null | undefined> | string | null | undefined; | ||
set?: (key: string, value: string, options?: CookieOptions) => Promise<void> | void; | ||
remove?: (key: string, options?: CookieOptions) => Promise<void> | void; | ||
set?: (key: string, value: string, options: CookieOptions) => Promise<void> | void; | ||
remove?: (key: string, options: CookieOptions) => Promise<void> | void; | ||
}; | ||
declare function createBrowserClient<Database = any, SchemaName extends string & keyof Database = 'public' extends keyof Database ? 'public' : string & keyof Database, Schema extends GenericSchema = Database[SchemaName] extends GenericSchema ? Database[SchemaName] : any>(supabaseUrl: string, supabaseKey: string, options?: SupabaseClientOptions<SchemaName> & { | ||
cookies: BrowserCookieMethods; | ||
cookies: CookieMethods; | ||
cookieOptions?: CookieOptionsWithName; | ||
@@ -30,3 +25,3 @@ isSingleton?: boolean; | ||
declare function createServerClient<Database = any, SchemaName extends string & keyof Database = 'public' extends keyof Database ? 'public' : string & keyof Database, Schema extends GenericSchema = Database[SchemaName] extends GenericSchema ? Database[SchemaName] : any>(supabaseUrl: string, supabaseKey: string, options: SupabaseClientOptions<SchemaName> & { | ||
cookies: ServerCookieMethods; | ||
cookies: CookieMethods; | ||
cookieOptions?: CookieOptionsWithName; | ||
@@ -39,2 +34,2 @@ }): _supabase_supabase_js.SupabaseClient<Database, SchemaName, Schema>; | ||
export { BrowserCookieMethods, CookieOptions, CookieOptionsWithName, DEFAULT_COOKIE_OPTIONS, ServerCookieMethods, createBrowserClient, createServerClient, isBrowser }; | ||
export { CookieMethods, CookieOptions, CookieOptionsWithName, DEFAULT_COOKIE_OPTIONS, createBrowserClient, createServerClient, isBrowser }; |
@@ -72,3 +72,3 @@ "use strict"; | ||
headers: { | ||
"X-Client-Info": `${"@supabase/ssr"}@${"0.0.2"}` | ||
"X-Client-Info": `${"@supabase/ssr"}@${"0.0.3"}` | ||
} | ||
@@ -84,3 +84,3 @@ }, | ||
if (typeof cookies.get === "function") { | ||
return await cookies.get(key) ?? null; | ||
return cookies.get(key); | ||
} | ||
@@ -163,11 +163,6 @@ if (isBrowser()) { | ||
const { cookies, cookieOptions, ...userDefinedClientOptions } = options; | ||
if (!cookies.get || !cookies.set || !cookies.remove) { | ||
throw new Error( | ||
"The Supabase client requires functions to get, set, and remove cookies in your specific framework!" | ||
); | ||
} | ||
const cookieClientOptions = { | ||
global: { | ||
headers: { | ||
"X-Client-Info": `${"@supabase/ssr"}@${"0.0.2"}` | ||
"X-Client-Info": `${"@supabase/ssr"}@${"0.0.3"}` | ||
} | ||
@@ -181,9 +176,21 @@ }, | ||
storage: { | ||
getItem: async (key) => await cookies.get(key) ?? null, | ||
setItem: async (key, value) => await cookies.set(key, value, { | ||
...DEFAULT_COOKIE_OPTIONS, | ||
...cookieOptions, | ||
maxAge: DEFAULT_COOKIE_OPTIONS.maxAge | ||
}), | ||
removeItem: async (key) => await cookies.remove(key, { ...DEFAULT_COOKIE_OPTIONS, ...cookieOptions, maxAge: 0 }) | ||
getItem: async (key) => { | ||
if (typeof cookies.get === "function") { | ||
return cookies.get(key); | ||
} | ||
}, | ||
setItem: async (key, value) => { | ||
if (typeof cookies.set === "function") { | ||
await cookies.set(key, value, { | ||
...DEFAULT_COOKIE_OPTIONS, | ||
...cookieOptions, | ||
maxAge: DEFAULT_COOKIE_OPTIONS.maxAge | ||
}); | ||
} | ||
}, | ||
removeItem: async (key) => { | ||
if (typeof cookies.remove === "function") { | ||
await cookies.remove(key, { ...DEFAULT_COOKIE_OPTIONS, ...cookieOptions, maxAge: 0 }); | ||
} | ||
} | ||
} | ||
@@ -190,0 +197,0 @@ } |
{ | ||
"name": "@supabase/ssr", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.mjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
396
36606