@orangecheck/auth-client 2.8.0 → 2.9.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.js CHANGED
@@ -771,6 +771,7 @@ var OcAddressInput = React3__namespace.forwardRef(
771
771
  }
772
772
  );
773
773
  var DEFAULT_AUTH_ORIGIN = "https://ochk.io";
774
+ var LINK_PROMPT_DISMISS_KEY = "oc:linkprompt-dismissed";
774
775
  function OcLinkedIdentities({
775
776
  authOrigin = DEFAULT_AUTH_ORIGIN,
776
777
  className,
@@ -1086,6 +1087,55 @@ function AttestationLink() {
1086
1087
  )
1087
1088
  ] });
1088
1089
  }
1090
+ function LinkPromptStep({
1091
+ method,
1092
+ didOc,
1093
+ authOrigin,
1094
+ onResolved
1095
+ }) {
1096
+ const [stage, setStage] = React3__namespace.useState("offer");
1097
+ function decline() {
1098
+ try {
1099
+ window.localStorage.setItem(LINK_PROMPT_DISMISS_KEY, String(Date.now()));
1100
+ } catch {
1101
+ }
1102
+ onResolved();
1103
+ }
1104
+ if (stage === "linking") {
1105
+ return method === "btc" ? /* @__PURE__ */ jsxRuntime.jsx(
1106
+ BtcLinkForm,
1107
+ {
1108
+ authOrigin,
1109
+ didOc,
1110
+ onDone: onResolved,
1111
+ onCancel: () => setStage("offer")
1112
+ }
1113
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
1114
+ EmailLinkForm,
1115
+ {
1116
+ authOrigin,
1117
+ onDone: onResolved,
1118
+ onCancel: () => setStage("offer")
1119
+ }
1120
+ );
1121
+ }
1122
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: panelStyle("accent"), "data-oc-linkprompt": method, children: [
1123
+ /* @__PURE__ */ jsxRuntime.jsx(SectionLabel, { tone: "success", children: "\xA7 you're signed in" }),
1124
+ /* @__PURE__ */ jsxRuntime.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." }),
1125
+ /* @__PURE__ */ jsxRuntime.jsxs(FormButtons, { children: [
1126
+ /* @__PURE__ */ jsxRuntime.jsx(
1127
+ "button",
1128
+ {
1129
+ type: "button",
1130
+ onClick: () => setStage("linking"),
1131
+ style: primaryBtnStyle(false),
1132
+ children: method === "btc" ? "link a Bitcoin address" : "link an email"
1133
+ }
1134
+ ),
1135
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: decline, style: ghostBtnStyle(false), children: "not now" })
1136
+ ] })
1137
+ ] });
1138
+ }
1089
1139
  function EmailLinkForm({
1090
1140
  authOrigin,
1091
1141
  onDone,
@@ -1594,7 +1644,7 @@ function OcSignIn({
1594
1644
  returnTo,
1595
1645
  onSuccess,
1596
1646
  resolveReturnTo,
1597
- linkPrompt,
1647
+ linkPrompt = true,
1598
1648
  authOrigin = "https://ochk.io",
1599
1649
  initialPath = "wallet",
1600
1650
  paths,
@@ -1619,18 +1669,39 @@ function OcSignIn({
1619
1669
  [resolveReturnTo, safeReturn]
1620
1670
  );
1621
1671
  const handleSuccess = React3__namespace.useCallback(
1622
- async (account, token) => {
1623
- if (onSuccess) {
1624
- onSuccess(account, token);
1625
- return;
1672
+ async (account, token, via) => {
1673
+ const proceed = () => {
1674
+ if (onSuccess) onSuccess(account, token);
1675
+ else void navigate(account);
1676
+ };
1677
+ let declined = false;
1678
+ try {
1679
+ declined = Boolean(window.localStorage.getItem(LINK_PROMPT_DISMISS_KEY));
1680
+ } catch {
1626
1681
  }
1627
- if (linkPrompt) {
1628
- setSignedIn(account);
1682
+ if (!linkPrompt || declined) {
1683
+ proceed();
1629
1684
  return;
1630
1685
  }
1631
- await navigate(account);
1686
+ try {
1687
+ const meRes = await fetch(`${authOrigin}/api/auth/me`, {
1688
+ credentials: "include",
1689
+ headers: { Accept: "application/json" }
1690
+ });
1691
+ const me = meRes.ok ? await meRes.json() : null;
1692
+ const acct = me?.account;
1693
+ const didOc = acct?.did_oc;
1694
+ const complementary = via === "email" ? "btc" : "email";
1695
+ const alreadyLinked = complementary === "btc" ? Boolean(acct?.primary_btc) : Boolean(acct?.has_email);
1696
+ if (didOc && !alreadyLinked) {
1697
+ setSignedIn({ method: complementary, didOc, proceed });
1698
+ return;
1699
+ }
1700
+ } catch {
1701
+ }
1702
+ proceed();
1632
1703
  },
1633
- [onSuccess, linkPrompt, navigate]
1704
+ [onSuccess, linkPrompt, navigate, authOrigin]
1634
1705
  );
1635
1706
  if (!walletEnabled && !emailEnabled) {
1636
1707
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -1661,8 +1732,10 @@ function OcSignIn({
1661
1732
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className, "data-oc-signin": "", children: /* @__PURE__ */ jsxRuntime.jsx(
1662
1733
  LinkPromptStep,
1663
1734
  {
1735
+ method: signedIn.method,
1736
+ didOc: signedIn.didOc,
1664
1737
  authOrigin,
1665
- onContinue: () => void navigate(signedIn)
1738
+ onResolved: signedIn.proceed
1666
1739
  }
1667
1740
  ) });
1668
1741
  }
@@ -1701,32 +1774,19 @@ function OcSignIn({
1701
1774
  {
1702
1775
  authOrigin,
1703
1776
  audience,
1704
- onSuccess: handleSuccess
1777
+ onSuccess: (a, t) => void handleSuccess(a, t, "wallet")
1705
1778
  }
1706
1779
  ),
1707
- showEmail && /* @__PURE__ */ jsxRuntime.jsx(EmailFlow, { authOrigin, onSuccess: handleSuccess })
1780
+ showEmail && /* @__PURE__ */ jsxRuntime.jsx(
1781
+ EmailFlow,
1782
+ {
1783
+ authOrigin,
1784
+ onSuccess: (a, t) => void handleSuccess(a, t, "email")
1785
+ }
1786
+ )
1708
1787
  ] })
1709
1788
  ] });
1710
1789
  }
1711
- function LinkPromptStep({
1712
- authOrigin,
1713
- onContinue
1714
- }) {
1715
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-oc-signin-linkprompt": "", children: [
1716
- /* @__PURE__ */ jsxRuntime.jsx(FlowHeader, { label: "\xA7 signed in \xB7 add a backup", children: "You're in. Linking a second way to sign in \u2014 your email or your Bitcoin wallet \u2014 is also your recovery path: lose one, the other still gets you in. Optional; skip with continue." }),
1717
- /* @__PURE__ */ jsxRuntime.jsx(OcLinkedIdentities, { authOrigin }),
1718
- /* @__PURE__ */ jsxRuntime.jsx(
1719
- "button",
1720
- {
1721
- type: "button",
1722
- onClick: onContinue,
1723
- style: submitStyle(false),
1724
- "data-oc-signin-continue": "",
1725
- children: "continue \u2192"
1726
- }
1727
- )
1728
- ] });
1729
- }
1730
1790
  function SigninTab({
1731
1791
  active,
1732
1792
  onClick,