@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.mjs CHANGED
@@ -749,6 +749,7 @@ 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";
752
753
  function OcLinkedIdentities({
753
754
  authOrigin = DEFAULT_AUTH_ORIGIN,
754
755
  className,
@@ -1064,6 +1065,55 @@ function AttestationLink() {
1064
1065
  )
1065
1066
  ] });
1066
1067
  }
1068
+ function LinkPromptStep({
1069
+ method,
1070
+ didOc,
1071
+ authOrigin,
1072
+ onResolved
1073
+ }) {
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(
1084
+ BtcLinkForm,
1085
+ {
1086
+ authOrigin,
1087
+ didOc,
1088
+ onDone: onResolved,
1089
+ onCancel: () => setStage("offer")
1090
+ }
1091
+ ) : /* @__PURE__ */ jsx(
1092
+ EmailLinkForm,
1093
+ {
1094
+ authOrigin,
1095
+ onDone: onResolved,
1096
+ onCancel: () => setStage("offer")
1097
+ }
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
+ ] })
1115
+ ] });
1116
+ }
1067
1117
  function EmailLinkForm({
1068
1118
  authOrigin,
1069
1119
  onDone,
@@ -1572,7 +1622,7 @@ function OcSignIn({
1572
1622
  returnTo,
1573
1623
  onSuccess,
1574
1624
  resolveReturnTo,
1575
- linkPrompt,
1625
+ linkPrompt = true,
1576
1626
  authOrigin = "https://ochk.io",
1577
1627
  initialPath = "wallet",
1578
1628
  paths,
@@ -1597,18 +1647,39 @@ function OcSignIn({
1597
1647
  [resolveReturnTo, safeReturn]
1598
1648
  );
1599
1649
  const handleSuccess = React3.useCallback(
1600
- async (account, token) => {
1601
- if (onSuccess) {
1602
- onSuccess(account, token);
1603
- return;
1650
+ async (account, token, via) => {
1651
+ const proceed = () => {
1652
+ if (onSuccess) onSuccess(account, token);
1653
+ else void navigate(account);
1654
+ };
1655
+ let declined = false;
1656
+ try {
1657
+ declined = Boolean(window.localStorage.getItem(LINK_PROMPT_DISMISS_KEY));
1658
+ } catch {
1604
1659
  }
1605
- if (linkPrompt) {
1606
- setSignedIn(account);
1660
+ if (!linkPrompt || declined) {
1661
+ proceed();
1607
1662
  return;
1608
1663
  }
1609
- await navigate(account);
1664
+ try {
1665
+ const meRes = await fetch(`${authOrigin}/api/auth/me`, {
1666
+ credentials: "include",
1667
+ headers: { Accept: "application/json" }
1668
+ });
1669
+ 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 });
1676
+ return;
1677
+ }
1678
+ } catch {
1679
+ }
1680
+ proceed();
1610
1681
  },
1611
- [onSuccess, linkPrompt, navigate]
1682
+ [onSuccess, linkPrompt, navigate, authOrigin]
1612
1683
  );
1613
1684
  if (!walletEnabled && !emailEnabled) {
1614
1685
  return /* @__PURE__ */ jsxs(
@@ -1639,8 +1710,10 @@ function OcSignIn({
1639
1710
  return /* @__PURE__ */ jsx("div", { className, "data-oc-signin": "", children: /* @__PURE__ */ jsx(
1640
1711
  LinkPromptStep,
1641
1712
  {
1713
+ method: signedIn.method,
1714
+ didOc: signedIn.didOc,
1642
1715
  authOrigin,
1643
- onContinue: () => void navigate(signedIn)
1716
+ onResolved: signedIn.proceed
1644
1717
  }
1645
1718
  ) });
1646
1719
  }
@@ -1679,32 +1752,19 @@ function OcSignIn({
1679
1752
  {
1680
1753
  authOrigin,
1681
1754
  audience,
1682
- onSuccess: handleSuccess
1755
+ onSuccess: (a, t) => void handleSuccess(a, t, "wallet")
1683
1756
  }
1684
1757
  ),
1685
- showEmail && /* @__PURE__ */ jsx(EmailFlow, { authOrigin, onSuccess: handleSuccess })
1758
+ showEmail && /* @__PURE__ */ jsx(
1759
+ EmailFlow,
1760
+ {
1761
+ authOrigin,
1762
+ onSuccess: (a, t) => void handleSuccess(a, t, "email")
1763
+ }
1764
+ )
1686
1765
  ] })
1687
1766
  ] });
1688
1767
  }
1689
- function LinkPromptStep({
1690
- authOrigin,
1691
- onContinue
1692
- }) {
1693
- return /* @__PURE__ */ jsxs("div", { "data-oc-signin-linkprompt": "", children: [
1694
- /* @__PURE__ */ 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." }),
1695
- /* @__PURE__ */ jsx(OcLinkedIdentities, { authOrigin }),
1696
- /* @__PURE__ */ jsx(
1697
- "button",
1698
- {
1699
- type: "button",
1700
- onClick: onContinue,
1701
- style: submitStyle(false),
1702
- "data-oc-signin-continue": "",
1703
- children: "continue \u2192"
1704
- }
1705
- )
1706
- ] });
1707
- }
1708
1768
  function SigninTab({
1709
1769
  active,
1710
1770
  onClick,