@orangecheck/auth-client 2.11.0 → 2.13.0
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.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +53 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { startRegistration, startAuthentication } from '@simplewebauthn/browser'
|
|
|
5
5
|
// src/provider.tsx
|
|
6
6
|
|
|
7
7
|
// src/types.ts
|
|
8
|
+
var DISPLAY_IDENTITY_KINDS = ["did", "btc", "email", "nostr"];
|
|
8
9
|
var DEFAULT_CONFIG = {
|
|
9
10
|
authOrigin: "https://ochk.io",
|
|
10
11
|
signInPath: "/signin",
|
|
@@ -22,6 +23,13 @@ function buildSignInUrl(cfg, returnTo) {
|
|
|
22
23
|
return u.toString();
|
|
23
24
|
}
|
|
24
25
|
var SessionContext = React3.createContext(null);
|
|
26
|
+
function normalizeDisplayIdentity(raw, didOc) {
|
|
27
|
+
const di = raw.display_identity ?? raw.displayIdentity;
|
|
28
|
+
if (di && typeof di === "object" && typeof di.value === "string" && di.value.length > 0 && typeof di.kind === "string" && DISPLAY_IDENTITY_KINDS.includes(di.kind)) {
|
|
29
|
+
return { kind: di.kind, value: di.value };
|
|
30
|
+
}
|
|
31
|
+
return { kind: "did", value: didOc };
|
|
32
|
+
}
|
|
25
33
|
function normalizeAccount(raw) {
|
|
26
34
|
if (!raw) return null;
|
|
27
35
|
const didOc = raw.did_oc ?? raw.didOc;
|
|
@@ -36,7 +44,8 @@ function normalizeAccount(raw) {
|
|
|
36
44
|
nostrNpub: raw.nostr_npub ?? raw.nostrNpub ?? null,
|
|
37
45
|
homeFederation: raw.home_federation_slug ?? raw.homeFederation ?? null,
|
|
38
46
|
signingMethod: raw.signing_method ?? raw.signingMethod ?? null,
|
|
39
|
-
isOwner: Boolean(raw.is_owner ?? raw.isOwner ?? false)
|
|
47
|
+
isOwner: Boolean(raw.is_owner ?? raw.isOwner ?? false),
|
|
48
|
+
displayIdentity: normalizeDisplayIdentity(raw, didOc)
|
|
40
49
|
};
|
|
41
50
|
}
|
|
42
51
|
function OcSessionProvider({
|
|
@@ -84,13 +93,41 @@ function OcSessionProvider({
|
|
|
84
93
|
try {
|
|
85
94
|
await fetch(`${cfg.authOrigin}${cfg.logoutPath}`, {
|
|
86
95
|
method: "POST",
|
|
87
|
-
credentials: "include"
|
|
96
|
+
credentials: "include",
|
|
97
|
+
// `keepalive` lets the logout round-trip complete even if
|
|
98
|
+
// the caller hard-navigates away in the same tick (e.g.
|
|
99
|
+
// `<OcAccountMenu>` redirects home immediately on sign-out).
|
|
100
|
+
// Without it the in-flight request is cancelled on unload
|
|
101
|
+
// and the `.ochk.io` cookie may never get cleared.
|
|
102
|
+
keepalive: true
|
|
88
103
|
});
|
|
89
104
|
} catch {
|
|
90
105
|
}
|
|
91
106
|
setAccount(null);
|
|
92
107
|
setStatus("anonymous");
|
|
93
108
|
}, [cfg.authOrigin, cfg.logoutPath]);
|
|
109
|
+
const setDisplayIdentity = React3.useCallback(
|
|
110
|
+
async (kind) => {
|
|
111
|
+
if (typeof window === "undefined") return;
|
|
112
|
+
const res = await fetch(`${cfg.authOrigin}/api/auth/account`, {
|
|
113
|
+
method: "PATCH",
|
|
114
|
+
credentials: "include",
|
|
115
|
+
headers: { "Content-Type": "application/json" },
|
|
116
|
+
body: JSON.stringify({ display_identity: kind })
|
|
117
|
+
});
|
|
118
|
+
if (!res.ok) {
|
|
119
|
+
let reason = `http_${res.status}`;
|
|
120
|
+
try {
|
|
121
|
+
const body = await res.json();
|
|
122
|
+
if (body.reason) reason = body.reason;
|
|
123
|
+
} catch {
|
|
124
|
+
}
|
|
125
|
+
throw new Error(`[@orangecheck/auth-client] setDisplayIdentity failed: ${reason}`);
|
|
126
|
+
}
|
|
127
|
+
await refresh();
|
|
128
|
+
},
|
|
129
|
+
[cfg.authOrigin, refresh]
|
|
130
|
+
);
|
|
94
131
|
const value = React3.useMemo(() => {
|
|
95
132
|
const returnTo = defaultReturnTo ?? (typeof window !== "undefined" ? window.location.href : void 0);
|
|
96
133
|
return {
|
|
@@ -99,9 +136,10 @@ function OcSessionProvider({
|
|
|
99
136
|
error,
|
|
100
137
|
refresh,
|
|
101
138
|
signOut,
|
|
139
|
+
setDisplayIdentity,
|
|
102
140
|
signInUrl: buildSignInUrl(cfg, returnTo)
|
|
103
141
|
};
|
|
104
|
-
}, [status, account, error, refresh, signOut, cfg, defaultReturnTo]);
|
|
142
|
+
}, [status, account, error, refresh, signOut, setDisplayIdentity, cfg, defaultReturnTo]);
|
|
105
143
|
return /* @__PURE__ */ jsx(SessionContext.Provider, { value, children });
|
|
106
144
|
}
|
|
107
145
|
function useOcSession() {
|
|
@@ -749,6 +787,16 @@ var OcAddressInput = React3.forwardRef(
|
|
|
749
787
|
}
|
|
750
788
|
);
|
|
751
789
|
var DEFAULT_AUTH_ORIGIN = "https://ochk.io";
|
|
790
|
+
async function fetchOcLinkedIdentities(opts) {
|
|
791
|
+
const authOrigin = opts?.authOrigin ?? DEFAULT_AUTH_ORIGIN;
|
|
792
|
+
const r = await fetch(`${authOrigin}/api/auth/identities`, {
|
|
793
|
+
credentials: "include"
|
|
794
|
+
});
|
|
795
|
+
if (r.status === 401) return [];
|
|
796
|
+
if (!r.ok) throw new Error(`identities fetch failed: http_${r.status}`);
|
|
797
|
+
const body = await r.json();
|
|
798
|
+
return body.linked ?? [];
|
|
799
|
+
}
|
|
752
800
|
function OcLinkedIdentities({
|
|
753
801
|
authOrigin = DEFAULT_AUTH_ORIGIN,
|
|
754
802
|
className,
|
|
@@ -2448,6 +2496,6 @@ function handleSudoRequired(body, args = {}) {
|
|
|
2448
2496
|
return false;
|
|
2449
2497
|
}
|
|
2450
2498
|
|
|
2451
|
-
export { DEFAULT_CONFIG, OcAccountChip, OcAccountPill, OcAddressInput, OcLinkedIdentities, OcSessionProvider, OcSignIn, OcSignInButton, buildSignInUrl, handleSudoRequired, redirectToSudo, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister };
|
|
2499
|
+
export { DEFAULT_CONFIG, DISPLAY_IDENTITY_KINDS, OcAccountChip, OcAccountPill, OcAddressInput, OcLinkedIdentities, OcSessionProvider, OcSignIn, OcSignInButton, buildSignInUrl, fetchOcLinkedIdentities, handleSudoRequired, redirectToSudo, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister };
|
|
2452
2500
|
//# sourceMappingURL=index.mjs.map
|
|
2453
2501
|
//# sourceMappingURL=index.mjs.map
|