@orangecheck/auth-client 2.12.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 +46 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -3
- 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({
|
|
@@ -97,6 +106,28 @@ function OcSessionProvider({
|
|
|
97
106
|
setAccount(null);
|
|
98
107
|
setStatus("anonymous");
|
|
99
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
|
+
);
|
|
100
131
|
const value = React3.useMemo(() => {
|
|
101
132
|
const returnTo = defaultReturnTo ?? (typeof window !== "undefined" ? window.location.href : void 0);
|
|
102
133
|
return {
|
|
@@ -105,9 +136,10 @@ function OcSessionProvider({
|
|
|
105
136
|
error,
|
|
106
137
|
refresh,
|
|
107
138
|
signOut,
|
|
139
|
+
setDisplayIdentity,
|
|
108
140
|
signInUrl: buildSignInUrl(cfg, returnTo)
|
|
109
141
|
};
|
|
110
|
-
}, [status, account, error, refresh, signOut, cfg, defaultReturnTo]);
|
|
142
|
+
}, [status, account, error, refresh, signOut, setDisplayIdentity, cfg, defaultReturnTo]);
|
|
111
143
|
return /* @__PURE__ */ jsx(SessionContext.Provider, { value, children });
|
|
112
144
|
}
|
|
113
145
|
function useOcSession() {
|
|
@@ -755,6 +787,16 @@ var OcAddressInput = React3.forwardRef(
|
|
|
755
787
|
}
|
|
756
788
|
);
|
|
757
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
|
+
}
|
|
758
800
|
function OcLinkedIdentities({
|
|
759
801
|
authOrigin = DEFAULT_AUTH_ORIGIN,
|
|
760
802
|
className,
|
|
@@ -2454,6 +2496,6 @@ function handleSudoRequired(body, args = {}) {
|
|
|
2454
2496
|
return false;
|
|
2455
2497
|
}
|
|
2456
2498
|
|
|
2457
|
-
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 };
|
|
2458
2500
|
//# sourceMappingURL=index.mjs.map
|
|
2459
2501
|
//# sourceMappingURL=index.mjs.map
|