@orangecheck/auth-client 2.47.0 → 2.49.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.js CHANGED
@@ -1493,6 +1493,18 @@ function ownWord(table, code) {
1493
1493
  }
1494
1494
 
1495
1495
  // src/refusal.ts
1496
+ var ENDED_ERRORS = {
1497
+ signed_out: "You were signed out while signing in. Sign in again.",
1498
+ account_deleted: "This account is being deleted, so you can't sign in to it.",
1499
+ no_roster: "An account in this browser was signed out while you were signing in, so this sign-in wasn't kept. Sign in again."
1500
+ };
1501
+ function endedSigninText(reason) {
1502
+ return ownWord(ENDED_ERRORS, reason);
1503
+ }
1504
+ var SEVERAL_SESSIONS_TEXT = "Your browser sent more than one ochk.io sign-in, so this account wasn't added. Check which account is signed in now, then try again.";
1505
+ function isSeveralSessions(err) {
1506
+ return err instanceof Error && err.message === "several_sessions";
1507
+ }
1496
1508
  var SIGNIN_ERRORS = {
1497
1509
  bad_request: "That doesn't look like a Bitcoin address.",
1498
1510
  invalid_challenge: "That signature doesn't match this address. Sign with the wallet that holds it.",
@@ -1514,10 +1526,14 @@ var SIGNIN_ERRORS = {
1514
1526
  wrong_code: "That code isn't right. Check the newest email from us.",
1515
1527
  replay: "That code was already used. Send a new one.",
1516
1528
  invalid_token: "That code is no longer valid. Send a new one.",
1517
- email_mismatch: "That code was sent to a different address. Send a new one."
1529
+ email_mismatch: "That code was sent to a different address. Send a new one.",
1530
+ several_sessions: SEVERAL_SESSIONS_TEXT,
1531
+ ...ENDED_ERRORS
1518
1532
  };
1519
1533
  var EMAIL_ERRORS = {
1520
- expired: "That code expired. Send a new one."
1534
+ expired: "That code expired. Send a new one.",
1535
+ signed_out: "You were signed out while signing in. Send a new code to sign in again.",
1536
+ no_roster: "An account in this browser was signed out while you were signing in, so this sign-in wasn't kept. Send a new code to sign in again."
1521
1537
  };
1522
1538
  var SUBMIT_ERRORS = {
1523
1539
  bad_request: "That signature couldn't be read. Copy it again, whole."
@@ -1932,6 +1948,7 @@ function EmailLinkForm({
1932
1948
  const [busy, setBusy] = React4__namespace.useState(false);
1933
1949
  const [err, setErr] = React4__namespace.useState(null);
1934
1950
  const [transfer, setTransfer] = React4__namespace.useState(false);
1951
+ const [moving, setMoving] = React4__namespace.useState(false);
1935
1952
  async function start() {
1936
1953
  setBusy(true);
1937
1954
  setErr(null);
@@ -2025,17 +2042,19 @@ function EmailLinkForm({
2025
2042
  TransferConfirm,
2026
2043
  {
2027
2044
  what: "email",
2045
+ next: "we send one more code to it",
2028
2046
  busy,
2029
- onConfirm: () => void verify(true),
2047
+ onConfirm: () => {
2048
+ setTransfer(false);
2049
+ setMoving(true);
2050
+ setCode("");
2051
+ void start();
2052
+ },
2030
2053
  onCancel,
2031
2054
  err
2032
2055
  }
2033
2056
  ) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2034
- /* @__PURE__ */ jsxRuntime.jsxs("p", { style: bodyStyle, children: [
2035
- "Enter the 6-digit code sent to ",
2036
- email,
2037
- "."
2038
- ] }),
2057
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: bodyStyle, children: moving ? `Enter the new 6-digit code sent to ${email} to move it here.` : `Enter the 6-digit code sent to ${email}.` }),
2039
2058
  /* @__PURE__ */ jsxRuntime.jsx(
2040
2059
  "input",
2041
2060
  {
@@ -2056,17 +2075,20 @@ function EmailLinkForm({
2056
2075
  "button",
2057
2076
  {
2058
2077
  type: "button",
2059
- onClick: () => void verify(false),
2078
+ onClick: () => void verify(moving),
2060
2079
  disabled: busy || code.length !== 6,
2061
2080
  style: primaryBtnStyle(busy || code.length !== 6),
2062
- children: busy ? "linking\u2026" : "verify + link"
2081
+ children: busy ? "linking\u2026" : moving ? "verify + transfer" : "verify + link"
2063
2082
  }
2064
2083
  ),
2065
2084
  /* @__PURE__ */ jsxRuntime.jsx(
2066
2085
  "button",
2067
2086
  {
2068
2087
  type: "button",
2069
- onClick: () => setStep("email"),
2088
+ onClick: () => {
2089
+ setStep("email");
2090
+ setMoving(false);
2091
+ },
2070
2092
  disabled: busy,
2071
2093
  style: ghostBtnStyle(busy),
2072
2094
  children: "back"
@@ -2087,14 +2109,15 @@ function BtcLinkForm({
2087
2109
  const [challenge, setChallenge] = React4__namespace.useState("");
2088
2110
  const [busy, setBusy] = React4__namespace.useState(false);
2089
2111
  const [err, setErr] = React4__namespace.useState(null);
2090
- const [pendingSig, setPendingSig] = React4__namespace.useState(null);
2091
- async function getChallenge() {
2112
+ const [elsewhere, setElsewhere] = React4__namespace.useState(false);
2113
+ const [moving, setMoving] = React4__namespace.useState(false);
2114
+ async function getChallenge(keepErr = false) {
2092
2115
  if (!didOc) {
2093
2116
  setErr("session not loaded yet \xB7 refresh and retry");
2094
2117
  return;
2095
2118
  }
2096
2119
  setBusy(true);
2097
- setErr(null);
2120
+ if (!keepErr) setErr(null);
2098
2121
  try {
2099
2122
  const r = await fetch(
2100
2123
  `${authOrigin}/api/challenge?addr=${encodeURIComponent(addr)}&purpose=link&audience=${encodeURIComponent(didOc)}`
@@ -2115,6 +2138,7 @@ function BtcLinkForm({
2115
2138
  async function postLink(sig, confirmTransfer) {
2116
2139
  setBusy(true);
2117
2140
  setErr(null);
2141
+ let answered = false;
2118
2142
  try {
2119
2143
  const r = await fetch(`${authOrigin}/api/auth/link/btc`, {
2120
2144
  method: "POST",
@@ -2128,7 +2152,7 @@ function BtcLinkForm({
2128
2152
  });
2129
2153
  const j = await r.json();
2130
2154
  if (r.status === 409 && j.reason === "address_linked_elsewhere") {
2131
- setPendingSig(sig);
2155
+ setElsewhere(true);
2132
2156
  setBusy(false);
2133
2157
  return;
2134
2158
  }
@@ -2138,11 +2162,15 @@ function BtcLinkForm({
2138
2162
  setBusy(false);
2139
2163
  return;
2140
2164
  }
2141
- if (!r.ok || !j.ok) throw new Error(j.reason ?? `http_${r.status}`);
2165
+ if (!r.ok || !j.ok) {
2166
+ answered = true;
2167
+ throw new Error(j.reason ?? `http_${r.status}`);
2168
+ }
2142
2169
  onDone();
2143
2170
  } catch (e) {
2144
2171
  setErr(failureMessage(e, "wallet", "submit", authOrigin));
2145
2172
  setBusy(false);
2173
+ if (answered) await getChallenge(true);
2146
2174
  }
2147
2175
  }
2148
2176
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: panelStyle("accent"), "data-oc-li-form": "btc", children: [
@@ -2176,21 +2204,25 @@ function BtcLinkForm({
2176
2204
  ),
2177
2205
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: onCancel, style: ghostBtnStyle(busy), children: "cancel" })
2178
2206
  ] })
2179
- ] }) : pendingSig ? /* @__PURE__ */ jsxRuntime.jsx(
2207
+ ] }) : elsewhere ? /* @__PURE__ */ jsxRuntime.jsx(
2180
2208
  TransferConfirm,
2181
2209
  {
2182
2210
  what: "bitcoin address",
2211
+ next: "you sign one more message with it",
2183
2212
  busy,
2184
- onConfirm: () => void postLink(pendingSig, true),
2213
+ onConfirm: () => {
2214
+ setElsewhere(false);
2215
+ setMoving(true);
2216
+ void getChallenge();
2217
+ },
2185
2218
  onCancel,
2186
2219
  err
2187
2220
  }
2188
2221
  ) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2189
2222
  /* @__PURE__ */ jsxRuntime.jsxs("p", { style: bodyStyle, children: [
2190
- "Sign the challenge with the wallet that controls",
2191
- " ",
2223
+ moving ? "Sign one more message with the wallet that controls " : "Sign the challenge with the wallet that controls ",
2192
2224
  /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontFamily: SIGNIN_FONT, wordBreak: "break-all" }, children: addr }),
2193
- "."
2225
+ moving ? " to move it here." : "."
2194
2226
  ] }),
2195
2227
  /* @__PURE__ */ jsxRuntime.jsx(
2196
2228
  LazyWalletButton,
@@ -2200,7 +2232,7 @@ function BtcLinkForm({
2200
2232
  showManual: true,
2201
2233
  layout: "list",
2202
2234
  heading: null,
2203
- onSigned: (sig) => void postLink(sig, false),
2235
+ onSigned: (sig) => void postLink(sig, moving),
2204
2236
  onError: (e) => setErr(e?.message ?? "wallet rejected")
2205
2237
  }
2206
2238
  ),
@@ -2212,6 +2244,7 @@ function BtcLinkForm({
2212
2244
  onClick: () => {
2213
2245
  setStep("request");
2214
2246
  setErr(null);
2247
+ setMoving(false);
2215
2248
  },
2216
2249
  disabled: busy,
2217
2250
  style: ghostBtnStyle(busy),
@@ -2223,6 +2256,7 @@ function BtcLinkForm({
2223
2256
  }
2224
2257
  function TransferConfirm({
2225
2258
  what,
2259
+ next,
2226
2260
  busy,
2227
2261
  onConfirm,
2228
2262
  onCancel,
@@ -2232,7 +2266,9 @@ function TransferConfirm({
2232
2266
  /* @__PURE__ */ jsxRuntime.jsxs("p", { style: bodyStyle, children: [
2233
2267
  "This ",
2234
2268
  what,
2235
- " is already linked to another OrangeCheck account. You've just proven control of it \u2014 you can transfer the link to this account under dual proof of control. The other account loses this sign-in path; its history stays verifiable. Continue?"
2269
+ " is already linked to another OrangeCheck account. You can transfer the link to this account under dual proof of control: ",
2270
+ next,
2271
+ ". The other account loses this sign-in path; its history stays verifiable. Continue?"
2236
2272
  ] }),
2237
2273
  err && /* @__PURE__ */ jsxRuntime.jsx(ErrorLine, { children: err }),
2238
2274
  /* @__PURE__ */ jsxRuntime.jsxs(FormButtons, { children: [
@@ -2272,7 +2308,7 @@ function LazyWalletButton(props) {
2272
2308
  return /* @__PURE__ */ jsxRuntime.jsx(ErrorLine, { children: "could not load wallet support \xB7 refresh to try again" });
2273
2309
  }
2274
2310
  if (!Comp) return /* @__PURE__ */ jsxRuntime.jsx("span", { style: hintStyle, children: "loading wallet options\u2026" });
2275
- return /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...props });
2311
+ return /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...props }, props.message);
2276
2312
  }
2277
2313
  function mask(value, kind) {
2278
2314
  if (kind === "email") {
@@ -2479,6 +2515,9 @@ var OAUTH_PROVIDER_NAMES = /* @__PURE__ */ new Map([
2479
2515
  function oauthErrorText(reason, retryAt, provider) {
2480
2516
  const cap = capText(reason, retryAt);
2481
2517
  if (cap) return cap;
2518
+ const ended = endedSigninText(reason);
2519
+ if (ended) return ended;
2520
+ if (reason === "several_sessions") return SEVERAL_SESSIONS_TEXT;
2482
2521
  if (reason === "email_code_required") {
2483
2522
  return "This email already has an orangecheck account. Sign in to it with an email code below.";
2484
2523
  }
@@ -2494,6 +2533,7 @@ function OcSignIn({
2494
2533
  resolveReturnTo,
2495
2534
  linkPrompt: linkPromptProp = true,
2496
2535
  add: addProp,
2536
+ onSeveralSessions,
2497
2537
  authOrigin = "https://ochk.io",
2498
2538
  initialPath,
2499
2539
  providersFirst = true,
@@ -2507,6 +2547,8 @@ function OcSignIn({
2507
2547
  const firstParty = mode === "first-party";
2508
2548
  const credentials = firstParty ? "omit" : "include";
2509
2549
  const linkPrompt = linkPromptProp && !firstParty;
2550
+ const providerSession = useOptionalOcSession();
2551
+ const recheck = onSeveralSessions ?? providerSession?.refresh;
2510
2552
  const [resolvedReturn, setResolvedReturn] = React4__namespace.useState(
2511
2553
  () => familyReturnTarget(returnTo) ?? safeReturnTo(returnTo)
2512
2554
  );
@@ -2763,6 +2805,7 @@ function OcSignIn({
2763
2805
  audience,
2764
2806
  add: addMode,
2765
2807
  credentials,
2808
+ onSeveralSessions: recheck,
2766
2809
  onSuccess: (a, t) => void handleSuccess(a, t, "wallet")
2767
2810
  }
2768
2811
  ),
@@ -2772,6 +2815,7 @@ function OcSignIn({
2772
2815
  authOrigin,
2773
2816
  add: addMode,
2774
2817
  credentials,
2818
+ onSeveralSessions: recheck,
2775
2819
  onSuccess: (a, t) => void handleSuccess(a, t, "email")
2776
2820
  }
2777
2821
  )
@@ -2962,6 +3006,11 @@ function ProviderSignIn({
2962
3006
  }
2963
3007
  );
2964
3008
  }
3009
+ function recheckAfter(err, recheck) {
3010
+ if (!recheck || !isSeveralSessions(err)) return;
3011
+ void Promise.resolve().then(recheck).catch(() => {
3012
+ });
3013
+ }
2965
3014
  async function loadAdapter() {
2966
3015
  return await import('@orangecheck/wallet-adapter');
2967
3016
  }
@@ -2973,7 +3022,8 @@ function WalletFlow({
2973
3022
  audience,
2974
3023
  add,
2975
3024
  credentials,
2976
- onSuccess
3025
+ onSuccess,
3026
+ onSeveralSessions
2977
3027
  }) {
2978
3028
  const uid = React4__namespace.useId();
2979
3029
  const ids = {
@@ -3082,6 +3132,7 @@ function WalletFlow({
3082
3132
  } catch (err) {
3083
3133
  setError(failureMessage(err, "wallet", step, authOrigin));
3084
3134
  setSubmitting(false);
3135
+ recheckAfter(err, onSeveralSessions);
3085
3136
  }
3086
3137
  }
3087
3138
  async function signInManual(e) {
@@ -3099,6 +3150,7 @@ function WalletFlow({
3099
3150
  } catch (err) {
3100
3151
  setError(failureMessage(err, "wallet", "submit", authOrigin));
3101
3152
  setSubmitting(false);
3153
+ recheckAfter(err, onSeveralSessions);
3102
3154
  }
3103
3155
  }
3104
3156
  async function copyMessage() {
@@ -3238,7 +3290,13 @@ function WalletFlow({
3238
3290
  ] });
3239
3291
  }
3240
3292
  var ALSO_LISTED_TEXT = "An account made with Google or GitHub also lists this email. If that account is yours, sign in with Google or GitHub and add this email there to confirm it.";
3241
- function EmailFlow({ authOrigin, add, credentials, onSuccess }) {
3293
+ function EmailFlow({
3294
+ authOrigin,
3295
+ add,
3296
+ credentials,
3297
+ onSuccess,
3298
+ onSeveralSessions
3299
+ }) {
3242
3300
  const uid = React4__namespace.useId();
3243
3301
  const [stage, setStage] = React4__namespace.useState("enter");
3244
3302
  const [email, setEmail] = React4__namespace.useState("");
@@ -3338,6 +3396,7 @@ function EmailFlow({ authOrigin, add, credentials, onSuccess }) {
3338
3396
  onSuccess(json.account, json.token);
3339
3397
  } catch (err) {
3340
3398
  setCodeError(failureMessage(err, "email", "submit", authOrigin));
3399
+ recheckAfter(err, onSeveralSessions);
3341
3400
  } finally {
3342
3401
  setSubmitting(false);
3343
3402
  }