@orangecheck/auth-client 2.24.1 → 2.25.1

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
@@ -1132,6 +1132,32 @@ var OcAddressInput = React3.forwardRef(
1132
1132
  );
1133
1133
  }
1134
1134
  );
1135
+
1136
+ // src/sudo.tsx
1137
+ function redirectToSudo(args = {}) {
1138
+ if (typeof window === "undefined") {
1139
+ throw new Error(
1140
+ "[@orangecheck/auth-client] redirectToSudo() requires a browser environment"
1141
+ );
1142
+ }
1143
+ const cfg = resolveConfig(args.config);
1144
+ const url = new URL("/sudo", cfg.authOrigin);
1145
+ const returnTo = args.returnTo ?? window.location.href;
1146
+ if (returnTo) url.searchParams.set("return_to", returnTo);
1147
+ if (args.purpose) url.searchParams.set("purpose", args.purpose);
1148
+ window.location.assign(url.toString());
1149
+ }
1150
+ function handleSudoRequired(body, args = {}) {
1151
+ if (body && body.reason === "sudo_required") {
1152
+ redirectToSudo(args);
1153
+ return true;
1154
+ }
1155
+ return false;
1156
+ }
1157
+ var SUDO_ACCOUNT_MISMATCH_MESSAGE = "Switch this tab to that account first \u2014 the confirmation on file is for a different one.";
1158
+ function isSudoAccountMismatch(body) {
1159
+ return body?.reason === "sudo_account_mismatch";
1160
+ }
1135
1161
  var DEFAULT_AUTH_ORIGIN = "https://ochk.io";
1136
1162
  async function fetchOcLinkedIdentities(opts) {
1137
1163
  const authOrigin = opts?.authOrigin ?? DEFAULT_AUTH_ORIGIN;
@@ -1558,6 +1584,12 @@ function EmailLinkForm({
1558
1584
  setBusy(false);
1559
1585
  return;
1560
1586
  }
1587
+ if (handleSudoRequired(j, { purpose: "link an email" })) return;
1588
+ if (isSudoAccountMismatch(j)) {
1589
+ setErr(SUDO_ACCOUNT_MISMATCH_MESSAGE);
1590
+ setBusy(false);
1591
+ return;
1592
+ }
1561
1593
  if (!r.ok || !j.ok) throw new Error(j.reason ?? `http_${r.status}`);
1562
1594
  onDone();
1563
1595
  } catch (e) {
@@ -1700,6 +1732,12 @@ function BtcLinkForm({
1700
1732
  setBusy(false);
1701
1733
  return;
1702
1734
  }
1735
+ if (handleSudoRequired(j, { purpose: "link a Bitcoin address" })) return;
1736
+ if (isSudoAccountMismatch(j)) {
1737
+ setErr(SUDO_ACCOUNT_MISMATCH_MESSAGE);
1738
+ setBusy(false);
1739
+ return;
1740
+ }
1703
1741
  if (!r.ok || !j.ok) throw new Error(j.reason ?? `http_${r.status}`);
1704
1742
  onDone();
1705
1743
  } catch (e) {
@@ -1830,7 +1868,7 @@ function LazyWalletButton(props) {
1830
1868
  };
1831
1869
  }, []);
1832
1870
  if (failed) {
1833
- return /* @__PURE__ */ jsx(ErrorLine, { children: "@orangecheck/wallet-adapter not installed \xB7 add it to your site to link a wallet" });
1871
+ return /* @__PURE__ */ jsx(ErrorLine, { children: "could not load wallet support \xB7 refresh to try again" });
1834
1872
  }
1835
1873
  if (!Comp) return /* @__PURE__ */ jsxs("span", { style: hintStyle, children: [
1836
1874
  "> ",
@@ -2487,7 +2525,7 @@ function WalletFlow({ authOrigin, audience, add, onSuccess }) {
2487
2525
  adapter = await import('@orangecheck/wallet-adapter');
2488
2526
  } catch {
2489
2527
  throw new Error(
2490
- "@orangecheck/wallet-adapter not installed \xB7 add it to your consumer site"
2528
+ "could not load wallet support \xB7 refresh to try again"
2491
2529
  );
2492
2530
  }
2493
2531
  const wallets = adapter.detectWallets().filter((w) => w.detected && w.id !== "manual");
@@ -3090,28 +3128,6 @@ function useStepUpAuth(opts) {
3090
3128
  return { status, error, stepUp, reset };
3091
3129
  }
3092
3130
 
3093
- // src/sudo.tsx
3094
- function redirectToSudo(args = {}) {
3095
- if (typeof window === "undefined") {
3096
- throw new Error(
3097
- "[@orangecheck/auth-client] redirectToSudo() requires a browser environment"
3098
- );
3099
- }
3100
- const cfg = resolveConfig(args.config);
3101
- const url = new URL("/sudo", cfg.authOrigin);
3102
- const returnTo = args.returnTo ?? window.location.href;
3103
- if (returnTo) url.searchParams.set("return_to", returnTo);
3104
- if (args.purpose) url.searchParams.set("purpose", args.purpose);
3105
- window.location.assign(url.toString());
3106
- }
3107
- function handleSudoRequired(body, args = {}) {
3108
- if (body && body.reason === "sudo_required") {
3109
- redirectToSudo(args);
3110
- return true;
3111
- }
3112
- return false;
3113
- }
3114
-
3115
- export { DEFAULT_CONFIG, DISPLAY_IDENTITY_KINDS, OcAccountChip, OcAccountPill, OcAddressInput, OcLinkedIdentities, OcSessionProvider, OcSignIn, OcSignInButton, TAB_ACCOUNT_HINT_KEY, TAB_ADOPT_HASH, TAB_SESSION_HEADER, TAB_SESSION_STORAGE_KEY, buildAddAccountUrl, buildSignInUrl, clearTabSession, consumeTabAccountHint, consumeTabAdoptMarker, familyReturnTarget, fetchOcLinkedIdentities, handleSudoRequired, installTabFetchInterceptor, installTabLinkDecorator, readTabSession, redirectToSudo, safeReturnTo, tabSessionHeader, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister, writeTabSession };
3131
+ export { DEFAULT_CONFIG, DISPLAY_IDENTITY_KINDS, OcAccountChip, OcAccountPill, OcAddressInput, OcLinkedIdentities, OcSessionProvider, OcSignIn, OcSignInButton, SUDO_ACCOUNT_MISMATCH_MESSAGE, TAB_ACCOUNT_HINT_KEY, TAB_ADOPT_HASH, TAB_SESSION_HEADER, TAB_SESSION_STORAGE_KEY, buildAddAccountUrl, buildSignInUrl, clearTabSession, consumeTabAccountHint, consumeTabAdoptMarker, familyReturnTarget, fetchOcLinkedIdentities, handleSudoRequired, installTabFetchInterceptor, installTabLinkDecorator, isSudoAccountMismatch, readTabSession, redirectToSudo, safeReturnTo, tabSessionHeader, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister, writeTabSession };
3116
3132
  //# sourceMappingURL=index.mjs.map
3117
3133
  //# sourceMappingURL=index.mjs.map