@calimero-network/mero-react 9.1.2 → 9.1.3

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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createContext, useMemo, useState, useRef, useCallback, useEffect, useContext } from 'react';
2
- import { LocalStorageTokenStore, parseAuthCallback, MeroJs, buildAuthLoginUrl, DEFAULT_LOCAL_NODE_PORTS, discoverLocalNodes, nodeEndpoint, compareSemver } from '@calimero-network/mero-js';
2
+ import { LocalStorageTokenStore, parseAuthCallback, MeroJs, buildAuthLoginUrl, DEFAULT_LOCAL_NODE_PORTS, discoverLocalNodes, nodeEndpoint, compareSemver, AuthRevokedError, HTTPError } from '@calimero-network/mero-js';
3
3
  export * from '@calimero-network/mero-js';
4
4
  export { CAPABILITIES, DEFAULT_LOCAL_NODE_PORTS, discoverLocalNodes, hasCap, localNodeUrl, nodeEndpoint, probeNodeHealth, withCap, withoutCap } from '@calimero-network/mero-js';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -498,7 +498,22 @@ function MeroProvider({
498
498
  const onError = (err) => {
499
499
  if (!active) return;
500
500
  setIsOnline(false);
501
- if (!err.message.includes("401")) return;
501
+ if (err instanceof AuthRevokedError) {
502
+ logout();
503
+ return;
504
+ }
505
+ if (err instanceof HTTPError && err.status === 403) {
506
+ if (err.headers?.get("x-auth-error") === "permission_denied") {
507
+ console.warn(
508
+ "[MeroProvider] This session cannot open an event stream (403 permission_denied): its token predates the context:subscribe grant. Logging out \u2014 a fresh login mints a key that can subscribe."
509
+ );
510
+ logout();
511
+ return;
512
+ }
513
+ return;
514
+ }
515
+ const status = err instanceof HTTPError ? err.status : null;
516
+ if (status !== 401 && !err.message.includes("401")) return;
502
517
  if (recoveringRef.current) return;
503
518
  recoveringRef.current = true;
504
519
  void (async () => {