@calimero-network/mero-react 10.1.1 → 10.1.2

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.cjs CHANGED
@@ -133,6 +133,15 @@ function resolveTokenAdoption(params) {
133
133
  return { adopt: false, reason: "stale" };
134
134
  }
135
135
 
136
+ // src/utils/desktop.ts
137
+ function isDesktopWindow() {
138
+ if (typeof window === "undefined") return false;
139
+ const w = window;
140
+ const internals = w.__TAURI_INTERNALS__;
141
+ const tauri = typeof internals === "object" && internals !== null && !(typeof Node !== "undefined" && internals instanceof Node) && typeof internals.invoke === "function";
142
+ return tauri || w.__TAURI_FETCH_PROXY_INJECTED__ === true;
143
+ }
144
+
136
145
  // src/storage/index.ts
137
146
  var STORAGE_KEYS = {
138
147
  ACCESS_TOKEN: "mero:access_token",
@@ -283,6 +292,21 @@ function clearAllStorage() {
283
292
  var MeroContext = react.createContext(null);
284
293
  var DEFAULT_REGISTRY_URL = "https://apps.calimero.network";
285
294
  var isBrowser = typeof window !== "undefined";
295
+ var DESKTOP_HOST = isDesktopWindow();
296
+ var parsedCallback = null;
297
+ function readAuthCallback() {
298
+ const href = window.location.href;
299
+ if (parsedCallback?.href !== href) {
300
+ parsedCallback = { href, result: meroJs.parseAuthCallback(href, { allowUnsolicited: DESKTOP_HOST }) };
301
+ }
302
+ return parsedCallback.result;
303
+ }
304
+ function clearAuthCallbackFromUrl() {
305
+ if (!new URLSearchParams(window.location.hash.slice(1)).has("access_token")) return;
306
+ const url = new URL(window.location.href);
307
+ url.searchParams.delete("auth_state");
308
+ window.history.replaceState({}, "", url.pathname + url.search);
309
+ }
286
310
  function getPermissionsForMode(mode) {
287
311
  switch (mode) {
288
312
  case "single-context" /* SingleContext */:
@@ -345,7 +369,7 @@ function MeroProvider({
345
369
  const recoveringRef = react.useRef(false);
346
370
  const callbackRef = react.useRef(void 0);
347
371
  if (callbackRef.current === void 0 && isBrowser) {
348
- callbackRef.current = meroJs.parseAuthCallback(window.location.href);
372
+ callbackRef.current = readAuthCallback();
349
373
  }
350
374
  const createMeroInstance = react.useCallback(
351
375
  (url) => {
@@ -478,6 +502,7 @@ function MeroProvider({
478
502
  };
479
503
  }, [delegated, contextId, packageName, registryUrl]);
480
504
  react.useEffect(() => {
505
+ if (isBrowser) clearAuthCallbackFromUrl();
481
506
  if (delegated) return;
482
507
  let active = true;
483
508
  const init = async () => {
@@ -492,9 +517,6 @@ function MeroProvider({
492
517
  initiated: initiatedNodeUrl,
493
518
  allowedNodeUrls
494
519
  });
495
- if (isBrowser) {
496
- window.history.replaceState({}, "", window.location.pathname + window.location.search);
497
- }
498
520
  callbackRef.current = null;
499
521
  if (rejected) {
500
522
  console.error(
@@ -1019,13 +1041,6 @@ function useAccountEnrolment({
1019
1041
  customWallet: walletOverride !== void 0
1020
1042
  };
1021
1043
  }
1022
-
1023
- // src/utils/desktop.ts
1024
- function isDesktopWindow() {
1025
- if (typeof window === "undefined") return false;
1026
- const w = window;
1027
- return "__TAURI_INTERNALS__" in w || w.__TAURI_FETCH_PROXY_INJECTED__ === true;
1028
- }
1029
1044
  var CUSTOM_SELECTION = "__custom__";
1030
1045
  var TABS = [
1031
1046
  { id: "node", label: "Node" },