@orangecheck/auth-client 2.24.1 → 2.25.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.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) {
@@ -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