@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.js +20 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -70,6 +70,20 @@ function normalizeRosterEntry(raw) {
|
|
|
70
70
|
lastSeenAt: raw.last_seen_at ?? raw.lastSeenAt ?? null
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
+
async function fetchHostRoster(cfg) {
|
|
74
|
+
try {
|
|
75
|
+
const res = await fetch(`${cfg.authOrigin}${cfg.mePath}`, {
|
|
76
|
+
method: "GET",
|
|
77
|
+
credentials: "include",
|
|
78
|
+
headers: { Accept: "application/json" }
|
|
79
|
+
});
|
|
80
|
+
if (!res.ok) return [];
|
|
81
|
+
const body = await res.json();
|
|
82
|
+
return Array.isArray(body.roster) ? body.roster.map(normalizeRosterEntry).filter((r) => r !== null) : [];
|
|
83
|
+
} catch {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
73
87
|
function normalizeAccount(raw) {
|
|
74
88
|
if (!raw) return null;
|
|
75
89
|
const didOc = raw.did_oc ?? raw.didOc;
|
|
@@ -125,11 +139,16 @@ function OcSessionProvider({
|
|
|
125
139
|
setRoster(rosterEntries);
|
|
126
140
|
setStatus(acct ? "authenticated" : "anonymous");
|
|
127
141
|
setError(null);
|
|
142
|
+
const currentOrigin = typeof window !== "undefined" ? window.location.origin : null;
|
|
143
|
+
if (acct && rosterEntries.length === 0 && currentOrigin !== null && !cfg.authOrigin.startsWith(currentOrigin)) {
|
|
144
|
+
const peers = await fetchHostRoster(cfg);
|
|
145
|
+
if (peers.length > 0) setRoster(peers);
|
|
146
|
+
}
|
|
128
147
|
} catch (err) {
|
|
129
148
|
setStatus("error");
|
|
130
149
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
131
150
|
}
|
|
132
|
-
}, [cfg
|
|
151
|
+
}, [cfg]);
|
|
133
152
|
React3__namespace.useEffect(() => {
|
|
134
153
|
void refresh();
|
|
135
154
|
}, [refresh]);
|