@orangecheck/auth-client 2.9.1 → 2.10.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
@@ -749,7 +749,6 @@ var OcAddressInput = React3.forwardRef(
749
749
  }
750
750
  );
751
751
  var DEFAULT_AUTH_ORIGIN = "https://ochk.io";
752
- var LINK_PROMPT_DISMISS_KEY = "oc:linkprompt-dismissed";
753
752
  function OcLinkedIdentities({
754
753
  authOrigin = DEFAULT_AUTH_ORIGIN,
755
754
  className,
@@ -1071,47 +1070,24 @@ function LinkPromptStep({
1071
1070
  authOrigin,
1072
1071
  onResolved
1073
1072
  }) {
1074
- const [stage, setStage] = React3.useState("offer");
1075
- function decline() {
1076
- try {
1077
- window.localStorage.setItem(LINK_PROMPT_DISMISS_KEY, String(Date.now()));
1078
- } catch {
1079
- }
1080
- onResolved();
1081
- }
1082
- if (stage === "linking") {
1083
- return method === "btc" ? /* @__PURE__ */ jsx(
1073
+ return /* @__PURE__ */ jsxs("div", { "data-oc-linkprompt": method, children: [
1074
+ /* @__PURE__ */ jsxs("div", { style: { ...panelStyle("success"), marginBottom: 16 }, children: [
1075
+ /* @__PURE__ */ jsx(SectionLabel, { tone: "success", children: "\xA7 signed in" }),
1076
+ /* @__PURE__ */ jsxs("p", { style: { ...bodyStyle, margin: 0 }, children: [
1077
+ "You asked to also link ",
1078
+ method === "btc" ? "a Bitcoin address" : "an email",
1079
+ " \u2014 here it is. Finish below, or cancel to head straight on."
1080
+ ] })
1081
+ ] }),
1082
+ method === "btc" ? /* @__PURE__ */ jsx(
1084
1083
  BtcLinkForm,
1085
1084
  {
1086
1085
  authOrigin,
1087
1086
  didOc,
1088
1087
  onDone: onResolved,
1089
- onCancel: () => setStage("offer")
1090
- }
1091
- ) : /* @__PURE__ */ jsx(
1092
- EmailLinkForm,
1093
- {
1094
- authOrigin,
1095
- onDone: onResolved,
1096
- onCancel: () => setStage("offer")
1088
+ onCancel: onResolved
1097
1089
  }
1098
- );
1099
- }
1100
- return /* @__PURE__ */ jsxs("div", { style: panelStyle("accent"), "data-oc-linkprompt": method, children: [
1101
- /* @__PURE__ */ jsx(SectionLabel, { tone: "success", children: "\xA7 you're signed in" }),
1102
- /* @__PURE__ */ jsx("p", { style: bodyStyle, children: method === "btc" ? "Optional \u2014 link a Bitcoin address and it becomes a second way to sign in, and unlocks your on-chain footprint. One wallet signature, right here. No pressure: you can always do this later from your account page." : "Optional \u2014 add your email as a backup way to sign in if you ever lose your wallet. One six-digit code, right here. No pressure: you can always do this later from your account page." }),
1103
- /* @__PURE__ */ jsxs(FormButtons, { children: [
1104
- /* @__PURE__ */ jsx(
1105
- "button",
1106
- {
1107
- type: "button",
1108
- onClick: () => setStage("linking"),
1109
- style: primaryBtnStyle(false),
1110
- children: method === "btc" ? "link a Bitcoin address" : "link an email"
1111
- }
1112
- ),
1113
- /* @__PURE__ */ jsx("button", { type: "button", onClick: decline, style: ghostBtnStyle(false), children: "not now" })
1114
- ] })
1090
+ ) : /* @__PURE__ */ jsx(EmailLinkForm, { authOrigin, onDone: onResolved, onCancel: onResolved })
1115
1091
  ] });
1116
1092
  }
1117
1093
  function EmailLinkForm({
@@ -1633,6 +1609,7 @@ function OcSignIn({
1633
1609
  const safeReturn = safeReturnTo(returnTo);
1634
1610
  const [path, setPath] = React3.useState(initialPath);
1635
1611
  const [signedIn, setSignedIn] = React3.useState(null);
1612
+ const [linkAlso, setLinkAlso] = React3.useState(false);
1636
1613
  const navigate = React3.useCallback(
1637
1614
  async (account) => {
1638
1615
  if (resolveReturnTo) {
@@ -1652,12 +1629,7 @@ function OcSignIn({
1652
1629
  if (onSuccess) onSuccess(account, token);
1653
1630
  else void navigate(account);
1654
1631
  };
1655
- let declined = false;
1656
- try {
1657
- declined = Boolean(window.localStorage.getItem(LINK_PROMPT_DISMISS_KEY));
1658
- } catch {
1659
- }
1660
- if (!linkPrompt || declined) {
1632
+ if (!linkPrompt || !linkAlso) {
1661
1633
  proceed();
1662
1634
  return;
1663
1635
  }
@@ -1667,19 +1639,20 @@ function OcSignIn({
1667
1639
  headers: { Accept: "application/json" }
1668
1640
  });
1669
1641
  const me = meRes.ok ? await meRes.json() : null;
1670
- const acct = me?.account;
1671
- const didOc = acct?.did_oc;
1672
- const complementary = via === "email" ? "btc" : "email";
1673
- const alreadyLinked = complementary === "btc" ? Boolean(acct?.primary_btc) : Boolean(acct?.has_email);
1674
- if (didOc && !alreadyLinked) {
1675
- setSignedIn({ method: complementary, didOc, proceed });
1642
+ const didOc = me?.account?.did_oc;
1643
+ if (didOc) {
1644
+ setSignedIn({
1645
+ method: via === "email" ? "btc" : "email",
1646
+ didOc,
1647
+ proceed
1648
+ });
1676
1649
  return;
1677
1650
  }
1678
1651
  } catch {
1679
1652
  }
1680
1653
  proceed();
1681
1654
  },
1682
- [onSuccess, linkPrompt, navigate, authOrigin]
1655
+ [onSuccess, linkPrompt, linkAlso, navigate, authOrigin]
1683
1656
  );
1684
1657
  if (!walletEnabled && !emailEnabled) {
1685
1658
  return /* @__PURE__ */ jsxs(
@@ -1720,6 +1693,7 @@ function OcSignIn({
1720
1693
  const showWallet = walletEnabled && (path === "wallet" || !emailEnabled);
1721
1694
  const showEmail = emailEnabled && (path === "email" || !walletEnabled);
1722
1695
  const bothEnabled = walletEnabled && emailEnabled;
1696
+ const activeMethod = !emailEnabled ? "wallet" : !walletEnabled ? "email" : path;
1723
1697
  return /* @__PURE__ */ jsxs("div", { className, "data-oc-signin": "", children: [
1724
1698
  bothEnabled && /* @__PURE__ */ jsxs(
1725
1699
  "div",
@@ -1762,6 +1736,24 @@ function OcSignIn({
1762
1736
  onSuccess: (a, t) => void handleSuccess(a, t, "email")
1763
1737
  }
1764
1738
  )
1739
+ ] }),
1740
+ linkPrompt && /* @__PURE__ */ jsxs("label", { "data-oc-signin-linkalso": "", style: linkAlsoStyle, children: [
1741
+ /* @__PURE__ */ jsx(
1742
+ "input",
1743
+ {
1744
+ type: "checkbox",
1745
+ checked: linkAlso,
1746
+ onChange: (e) => setLinkAlso(e.target.checked),
1747
+ style: { marginTop: 2, accentColor: "var(--primary, #f97316)" }
1748
+ }
1749
+ ),
1750
+ /* @__PURE__ */ jsxs("span", { children: [
1751
+ "After signing in, also link",
1752
+ " ",
1753
+ activeMethod === "email" ? "a Bitcoin wallet" : "an email",
1754
+ " ",
1755
+ /* @__PURE__ */ jsx("span", { style: { opacity: 0.65 }, children: "\u2014 optional, one more signature." })
1756
+ ] })
1765
1757
  ] })
1766
1758
  ] });
1767
1759
  }
@@ -2113,6 +2105,19 @@ var inputStyle2 = {
2113
2105
  fontSize: 16,
2114
2106
  outline: "none"
2115
2107
  };
2108
+ var linkAlsoStyle = {
2109
+ display: "flex",
2110
+ alignItems: "flex-start",
2111
+ gap: 8,
2112
+ marginTop: 16,
2113
+ paddingTop: 14,
2114
+ borderTop: "1px solid var(--border, #27272a)",
2115
+ color: "var(--muted-foreground, #a1a1aa)",
2116
+ fontFamily: "ui-monospace, SFMono-Regular, monospace",
2117
+ fontSize: 12,
2118
+ lineHeight: 1.5,
2119
+ cursor: "pointer"
2120
+ };
2116
2121
  function submitStyle(disabled) {
2117
2122
  return {
2118
2123
  marginTop: 12,