@updatedev/ssr
Version:
Update SSR SDK
68 lines • 2.73 kB
JavaScript
import {
createClient
} from "@updatedev/js/supabase";
import { createStorageFromOptions } from "@supabase/ssr/dist/main/cookies";
import { VERSION } from "@supabase/ssr/dist/main/version";
import { isBrowser } from "@supabase/ssr/dist/main/utils";
let cachedBrowserClient;
const createBrowserClient = (updateApiKey, supabaseUrl, supabaseAnonKey, options) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
const shouldUseSingleton = ((_a = options == null ? void 0 : options.supabase) == null ? void 0 : _a.isSingleton) === true || (!(options == null ? void 0 : options.supabase) || !("isSingleton" in (options.supabase || {}))) && isBrowser();
if (shouldUseSingleton && cachedBrowserClient) {
return cachedBrowserClient;
}
if (!updateApiKey) {
throw new Error("An Update API Key is required");
}
if (!supabaseUrl || !supabaseAnonKey) {
throw new Error("A Supabase URL and Anon Key are required");
}
const { storage } = createStorageFromOptions(
{
cookies: options == null ? void 0 : options.cookies,
cookieOptions: (_b = options == null ? void 0 : options.supabase) == null ? void 0 : _b.cookieOptions,
cookieEncoding: (_d = (_c = options == null ? void 0 : options.supabase) == null ? void 0 : _c.cookieEncoding) != null ? _d : "base64url"
},
false
);
const supabaseOptions = {
...options == null ? void 0 : options.supabase,
global: {
...(_e = options == null ? void 0 : options.supabase) == null ? void 0 : _e.global,
headers: {
...(_g = (_f = options == null ? void 0 : options.supabase) == null ? void 0 : _f.global) == null ? void 0 : _g.headers,
"X-Client-Info": `supabase-ssr/${VERSION} createBrowserClient`
}
},
auth: {
...(_h = options == null ? void 0 : options.supabase) == null ? void 0 : _h.auth,
...((_j = (_i = options == null ? void 0 : options.supabase) == null ? void 0 : _i.cookieOptions) == null ? void 0 : _j.name) ? { storageKey: options.supabase.cookieOptions.name } : null,
flowType: "pkce",
autoRefreshToken: isBrowser(),
detectSessionInUrl: isBrowser(),
persistSession: true,
storage
}
};
const client = createClient(
updateApiKey,
supabaseUrl,
supabaseAnonKey,
{
...options,
storage: {
getAll: (_k = options == null ? void 0 : options.cookies) == null ? void 0 : _k.getAll,
setAll: (_l = options == null ? void 0 : options.cookies) == null ? void 0 : _l.setAll
},
supabase: supabaseOptions
}
);
if (shouldUseSingleton) {
cachedBrowserClient = client;
}
return client;
};
export {
createBrowserClient
};
//# sourceMappingURL=createBrowserClient.js.map