decane-connect-kit 2.2.4 → 2.2.5

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.cjs CHANGED
@@ -4888,7 +4888,10 @@ function SignInView({
4888
4888
  authMethods,
4889
4889
  resumeHint,
4890
4890
  customAuthLabel,
4891
- onCustomAuthSignIn
4891
+ onCustomAuthSignIn,
4892
+ canUsePasskey,
4893
+ passkeyAddress,
4894
+ onPasskeySignIn
4892
4895
  }) {
4893
4896
  const [googleLoading, setGoogleLoading] = (0, import_react3.useState)(false);
4894
4897
  const [email, setEmail] = (0, import_react3.useState)("");
@@ -4896,7 +4899,25 @@ function SignInView({
4896
4899
  const [emailSent, setEmailSent] = (0, import_react3.useState)(false);
4897
4900
  const [emailLoading, setEmailLoading] = (0, import_react3.useState)(false);
4898
4901
  const [customLoading, setCustomLoading] = (0, import_react3.useState)(false);
4902
+ const [passkeyLoading, setPasskeyLoading] = (0, import_react3.useState)(false);
4903
+ const [showOtherMethods, setShowOtherMethods] = (0, import_react3.useState)(false);
4899
4904
  const [error, setError] = (0, import_react3.useState)("");
4905
+ const passkeyFirst = !!canUsePasskey && !!onPasskeySignIn && !showOtherMethods;
4906
+ async function handlePasskey() {
4907
+ if (!onPasskeySignIn) return;
4908
+ setError("");
4909
+ setPasskeyLoading(true);
4910
+ try {
4911
+ await onPasskeySignIn();
4912
+ } catch (e) {
4913
+ const err = e;
4914
+ if (err?.name !== "UserCancelledError") {
4915
+ setError(err?.message ?? "Passkey sign-in failed");
4916
+ setShowOtherMethods(true);
4917
+ }
4918
+ setPasskeyLoading(false);
4919
+ }
4920
+ }
4900
4921
  async function handleGoogle() {
4901
4922
  setError("");
4902
4923
  setGoogleLoading(true);
@@ -4956,7 +4977,47 @@ function SignInView({
4956
4977
  fontFamily: "inherit",
4957
4978
  boxSizing: "border-box"
4958
4979
  };
4959
- return /* @__PURE__ */ import_react3.default.createElement("div", { style: { padding: "0 16px 16px" } }, resumeHint && /* @__PURE__ */ import_react3.default.createElement("div", { style: { fontSize: 12, color: "var(--dc-text-muted)", marginBottom: 12, textAlign: "center" } }, "Welcome back \u2014 sign in again to resume ", resumeHint), authMethods.includes("google") && /* @__PURE__ */ import_react3.default.createElement(
4980
+ return /* @__PURE__ */ import_react3.default.createElement("div", { style: { padding: "0 16px 16px" } }, resumeHint && !passkeyFirst && /* @__PURE__ */ import_react3.default.createElement("div", { style: { fontSize: 12, color: "var(--dc-text-muted)", marginBottom: 12, textAlign: "center" } }, "Welcome back \u2014 sign in again to resume ", resumeHint), passkeyFirst && /* @__PURE__ */ import_react3.default.createElement("div", null, /* @__PURE__ */ import_react3.default.createElement("div", { style: { fontSize: 12, color: "var(--dc-text-muted)", marginBottom: 12, textAlign: "center" } }, "Welcome back \u2014 unlock to resume", passkeyAddress ? ` ${passkeyAddress.slice(0, 6)}\u2026${passkeyAddress.slice(-4)}` : ""), /* @__PURE__ */ import_react3.default.createElement(
4981
+ "button",
4982
+ {
4983
+ onClick: handlePasskey,
4984
+ disabled: passkeyLoading,
4985
+ style: {
4986
+ width: "100%",
4987
+ padding: "11px 0",
4988
+ background: "var(--dc-accent)",
4989
+ color: "var(--dc-accent-text)",
4990
+ border: "none",
4991
+ borderRadius: 10,
4992
+ fontSize: 13,
4993
+ fontWeight: 700,
4994
+ cursor: passkeyLoading ? "not-allowed" : "pointer",
4995
+ opacity: passkeyLoading ? 0.7 : 1,
4996
+ fontFamily: "inherit",
4997
+ display: "flex",
4998
+ alignItems: "center",
4999
+ justifyContent: "center",
5000
+ gap: 7
5001
+ }
5002
+ },
5003
+ passkeyLoading ? "Verifying\u2026" : "\u{1F513} Continue with passkey"
5004
+ ), /* @__PURE__ */ import_react3.default.createElement(
5005
+ "button",
5006
+ {
5007
+ onClick: () => setShowOtherMethods(true),
5008
+ style: {
5009
+ width: "100%",
5010
+ marginTop: 10,
5011
+ background: "none",
5012
+ border: "none",
5013
+ color: "var(--dc-text-muted)",
5014
+ fontSize: 12,
5015
+ cursor: "pointer",
5016
+ fontFamily: "inherit"
5017
+ }
5018
+ },
5019
+ "Use email or Google instead"
5020
+ ), error && /* @__PURE__ */ import_react3.default.createElement("div", { style: { marginTop: 10, fontSize: 12, color: "var(--dc-danger, #ff5533)" } }, error)), !passkeyFirst && authMethods.includes("google") && /* @__PURE__ */ import_react3.default.createElement(
4960
5021
  "button",
4961
5022
  {
4962
5023
  onClick: handleGoogle,
@@ -4977,7 +5038,7 @@ function SignInView({
4977
5038
  }
4978
5039
  },
4979
5040
  googleLoading ? "Redirecting\u2026" : "Continue with Google"
4980
- ), authMethods.includes("email") && /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, authMethods.includes("google") && /* @__PURE__ */ import_react3.default.createElement("div", { style: { textAlign: "center", color: "var(--dc-text-muted)", fontSize: 12, margin: "10px 0" } }, "\u2014 or \u2014"), !emailSent ? /* @__PURE__ */ import_react3.default.createElement("form", { onSubmit: handleEmailStart, style: { display: "flex", gap: 8 } }, /* @__PURE__ */ import_react3.default.createElement(
5041
+ ), !passkeyFirst && authMethods.includes("email") && /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, authMethods.includes("google") && /* @__PURE__ */ import_react3.default.createElement("div", { style: { textAlign: "center", color: "var(--dc-text-muted)", fontSize: 12, margin: "10px 0" } }, "\u2014 or \u2014"), !emailSent ? /* @__PURE__ */ import_react3.default.createElement("form", { onSubmit: handleEmailStart, style: { display: "flex", gap: 8 } }, /* @__PURE__ */ import_react3.default.createElement(
4981
5042
  "input",
4982
5043
  {
4983
5044
  type: "email",
@@ -5016,7 +5077,7 @@ function SignInView({
5016
5077
  fontWeight: 700,
5017
5078
  cursor: "pointer",
5018
5079
  fontFamily: "inherit"
5019
- } }, emailLoading ? "\u2026" : "Verify"))), customAuthLabel && onCustomAuthSignIn && /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, (authMethods.includes("google") || authMethods.includes("email")) && /* @__PURE__ */ import_react3.default.createElement("div", { style: { textAlign: "center", color: "var(--dc-text-muted)", fontSize: 12, margin: "10px 0" } }, "\u2014 or \u2014"), /* @__PURE__ */ import_react3.default.createElement(
5080
+ } }, emailLoading ? "\u2026" : "Verify"))), !passkeyFirst && customAuthLabel && onCustomAuthSignIn && /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, (authMethods.includes("google") || authMethods.includes("email")) && /* @__PURE__ */ import_react3.default.createElement("div", { style: { textAlign: "center", color: "var(--dc-text-muted)", fontSize: 12, margin: "10px 0" } }, "\u2014 or \u2014"), /* @__PURE__ */ import_react3.default.createElement(
5020
5081
  "button",
5021
5082
  {
5022
5083
  onClick: handleCustomAuth,
@@ -5155,6 +5216,9 @@ function SocialWalletModal({
5155
5216
  authMethods = ["google", "email"],
5156
5217
  customAuthLabel,
5157
5218
  onCustomAuthSignIn,
5219
+ canUsePasskey,
5220
+ passkeyAddress,
5221
+ onPasskeySignIn,
5158
5222
  onRotateShares,
5159
5223
  onExportPortableBackup,
5160
5224
  rpcUrls,
@@ -5285,7 +5349,10 @@ function SocialWalletModal({
5285
5349
  authMethods,
5286
5350
  resumeHint: socialAuth.needsReconnect ? "your wallet" : void 0,
5287
5351
  customAuthLabel,
5288
- onCustomAuthSignIn
5352
+ onCustomAuthSignIn,
5353
+ canUsePasskey,
5354
+ passkeyAddress,
5355
+ onPasskeySignIn
5289
5356
  }
5290
5357
  ) : /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, /* @__PURE__ */ import_react3.default.createElement("div", { style: {
5291
5358
  margin: "0 16px 14px",
@@ -5673,6 +5740,9 @@ function DecaneKit({ config, children }) {
5673
5740
  onEmailStart: connectWithEmail,
5674
5741
  onEmailVerify: verifyEmailCode2,
5675
5742
  authMethods: config?.social?.authMethods ?? ["google", "email"],
5743
+ canUsePasskey: socialAuth.canUsePasskey,
5744
+ passkeyAddress: socialAuth.addresses?.evm ?? socialAuth.addresses?.solana ?? null,
5745
+ onPasskeySignIn: signInWithPasskey,
5676
5746
  onRotateShares: socialRotateShares,
5677
5747
  onExportPortableBackup: socialExportPortableBackup,
5678
5748
  rpcUrls: config?.social?.rpcUrls,
@@ -5702,6 +5772,7 @@ function useSocialAuth() {
5702
5772
  connectWithToken,
5703
5773
  customAuthLabel,
5704
5774
  connectWithCustomAuth,
5775
+ signInWithPasskey: ctxSignInWithPasskey,
5705
5776
  socialUnlock,
5706
5777
  socialDisconnect
5707
5778
  } = useDecaneContext();
@@ -5770,6 +5841,15 @@ function useSocialAuth() {
5770
5841
  setCustomLoading(false);
5771
5842
  }
5772
5843
  }, [connectWithCustomAuth]);
5844
+ const signInWithPasskey = (0, import_react5.useCallback)(async () => {
5845
+ setError(null);
5846
+ try {
5847
+ await ctxSignInWithPasskey();
5848
+ } catch (e) {
5849
+ setError(e.message);
5850
+ throw e;
5851
+ }
5852
+ }, [ctxSignInWithPasskey]);
5773
5853
  const unlock = (0, import_react5.useCallback)(async () => {
5774
5854
  setError(null);
5775
5855
  try {
@@ -5794,6 +5874,8 @@ function useSocialAuth() {
5794
5874
  isNewUser: socialAuth.isNewUser,
5795
5875
  addresses: socialAuth.addresses,
5796
5876
  sessionExpiresAt: socialAuth.sessionExpiresAt,
5877
+ // True when this device can skip the full sign-in and resume with a passkey.
5878
+ canUsePasskey: socialAuth.canUsePasskey,
5797
5879
  // True when addresses are known (from a previous visit) but there's no
5798
5880
  // live session — unlock() will always throw in this state (every
5799
5881
  // unlock requires a fresh JWT, and JWTs are never persisted). Route
@@ -5811,6 +5893,7 @@ function useSocialAuth() {
5811
5893
  confirmEmailCode,
5812
5894
  signInWithToken,
5813
5895
  signInWithCustomAuth: connectWithCustomAuth ? signInWithCustomAuth : void 0,
5896
+ signInWithPasskey,
5814
5897
  unlock,
5815
5898
  disconnect
5816
5899
  };