@erikey/react 0.2.8 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,12 +1,3 @@
1
- if (typeof globalThis.require === "undefined") {
2
- globalThis.require = function(m) {
3
- if (m === "react") return globalThis.__ERIKEY_REACT__;
4
- if (m === "react-dom") return globalThis.__ERIKEY_REACT_DOM__;
5
- throw new Error("[erikey/react] Dynamic require of " + m + " is not supported");
6
- };
7
- }
8
- import "./chunk-K57QXNQP.mjs";
9
-
10
1
  // ../../../node_modules/.pnpm/@better-fetch+fetch@1.1.18/node_modules/@better-fetch/fetch/dist/index.js
11
2
  var __defProp = Object.defineProperty;
12
3
  var __defProps = Object.defineProperties;
@@ -1799,55 +1790,10 @@ function createAuthClient2(config) {
1799
1790
  });
1800
1791
  }
1801
1792
 
1802
- // ../../sandpack-auth/dist/client/index.js
1803
- function shouldUseBearerAuth2(authApiUrl) {
1804
- if (typeof window === "undefined") {
1805
- return false;
1806
- }
1807
- try {
1808
- const currentOrigin = window.location.origin;
1809
- const authOrigin = new URL(authApiUrl).origin;
1810
- const isCrossOrigin = currentOrigin !== authOrigin;
1811
- if (isCrossOrigin) {
1812
- console.log("[Sandpack Auth] Cross-origin detected:", {
1813
- current: currentOrigin,
1814
- auth: authOrigin
1815
- });
1816
- }
1817
- return isCrossOrigin;
1818
- } catch (error) {
1819
- console.error("[Sandpack Auth] Failed to check origin:", error);
1820
- return false;
1821
- }
1822
- }
1823
- function getStorageKey2(projectId) {
1824
- return `erikey.session.${projectId}`;
1825
- }
1826
- function getStoredToken2(projectId) {
1827
- const key = getStorageKey2(projectId);
1828
- const stored = localStorage.getItem(key);
1829
- if (!stored) {
1830
- return null;
1831
- }
1832
- try {
1833
- const session = JSON.parse(stored);
1834
- if (new Date(session.expiresAt) < /* @__PURE__ */ new Date()) {
1835
- console.log("[Sandpack Auth] Token expired, removing from localStorage");
1836
- localStorage.removeItem(key);
1837
- return null;
1838
- }
1839
- return session.token;
1840
- } catch (error) {
1841
- console.error("[Sandpack Auth] Failed to parse stored session:", error);
1842
- localStorage.removeItem(key);
1843
- return null;
1844
- }
1845
- }
1846
-
1847
1793
  // src/kv-client.ts
1848
1794
  function createKvClient(config) {
1849
1795
  const { projectId, baseUrl = "https://auth.erikey.com" } = config;
1850
- const useBearerAuth = shouldUseBearerAuth2(baseUrl);
1796
+ const useBearerAuth = shouldUseBearerAuth(baseUrl);
1851
1797
  const fetchWithAuth = async (endpoint, options) => {
1852
1798
  const headers = {
1853
1799
  "Content-Type": "application/json",
@@ -1855,7 +1801,7 @@ function createKvClient(config) {
1855
1801
  ...options?.headers || {}
1856
1802
  };
1857
1803
  if (useBearerAuth) {
1858
- const token = getStoredToken2(projectId);
1804
+ const token = getStoredToken(projectId);
1859
1805
  if (token) {
1860
1806
  headers["Authorization"] = `Bearer ${token}`;
1861
1807
  }