UNPKG

@updatedev/ssr

Version:
90 lines 3.9 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var createBrowserClient_exports = {}; __export(createBrowserClient_exports, { createBrowserClient: () => createBrowserClient }); module.exports = __toCommonJS(createBrowserClient_exports); var import_supabase = require("@updatedev/js/supabase"); var import_cookies = require("@supabase/ssr/dist/main/cookies"); var import_version = require("@supabase/ssr/dist/main/version"); var import_utils = require("@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 || {}))) && (0, import_utils.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 } = (0, import_cookies.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/${import_version.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: (0, import_utils.isBrowser)(), detectSessionInUrl: (0, import_utils.isBrowser)(), persistSession: true, storage } }; const client = (0, import_supabase.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; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { createBrowserClient }); //# sourceMappingURL=createBrowserClient.js.map