@orangecheck/auth-client 2.17.1 → 2.17.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.mjs CHANGED
@@ -48,6 +48,20 @@ function normalizeRosterEntry(raw) {
48
48
  lastSeenAt: raw.last_seen_at ?? raw.lastSeenAt ?? null
49
49
  };
50
50
  }
51
+ async function fetchHostRoster(cfg) {
52
+ try {
53
+ const res = await fetch(`${cfg.authOrigin}${cfg.mePath}`, {
54
+ method: "GET",
55
+ credentials: "include",
56
+ headers: { Accept: "application/json" }
57
+ });
58
+ if (!res.ok) return [];
59
+ const body = await res.json();
60
+ return Array.isArray(body.roster) ? body.roster.map(normalizeRosterEntry).filter((r) => r !== null) : [];
61
+ } catch {
62
+ return [];
63
+ }
64
+ }
51
65
  function normalizeAccount(raw) {
52
66
  if (!raw) return null;
53
67
  const didOc = raw.did_oc ?? raw.didOc;
@@ -103,11 +117,16 @@ function OcSessionProvider({
103
117
  setRoster(rosterEntries);
104
118
  setStatus(acct ? "authenticated" : "anonymous");
105
119
  setError(null);
120
+ const currentOrigin = typeof window !== "undefined" ? window.location.origin : null;
121
+ if (acct && rosterEntries.length === 0 && currentOrigin !== null && !cfg.authOrigin.startsWith(currentOrigin)) {
122
+ const peers = await fetchHostRoster(cfg);
123
+ if (peers.length > 0) setRoster(peers);
124
+ }
106
125
  } catch (err) {
107
126
  setStatus("error");
108
127
  setError(err instanceof Error ? err : new Error(String(err)));
109
128
  }
110
- }, [cfg.mePath]);
129
+ }, [cfg]);
111
130
  React3.useEffect(() => {
112
131
  void refresh();
113
132
  }, [refresh]);