@turnkey/sdk-react 3.0.6 → 4.0.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/dist/components/auth/Apple.d.ts.map +1 -1
  3. package/dist/components/auth/Apple.js +21 -8
  4. package/dist/components/auth/Apple.js.map +1 -1
  5. package/dist/components/auth/Apple.mjs +27 -11
  6. package/dist/components/auth/Apple.mjs.map +1 -1
  7. package/dist/components/auth/Auth.d.ts +8 -1
  8. package/dist/components/auth/Auth.d.ts.map +1 -1
  9. package/dist/components/auth/Auth.js +117 -56
  10. package/dist/components/auth/Auth.js.map +1 -1
  11. package/dist/components/auth/Auth.mjs +251 -182
  12. package/dist/components/auth/Auth.mjs.map +1 -1
  13. package/dist/components/auth/Facebook.d.ts.map +1 -1
  14. package/dist/components/auth/Facebook.js +19 -8
  15. package/dist/components/auth/Facebook.js.map +1 -1
  16. package/dist/components/auth/Facebook.mjs +35 -21
  17. package/dist/components/auth/Facebook.mjs.map +1 -1
  18. package/dist/components/auth/Google.d.ts.map +1 -1
  19. package/dist/components/auth/Google.js +20 -9
  20. package/dist/components/auth/Google.js.map +1 -1
  21. package/dist/components/auth/Google.mjs +28 -14
  22. package/dist/components/auth/Google.mjs.map +1 -1
  23. package/dist/components/auth/OtpVerification.d.ts +1 -2
  24. package/dist/components/auth/OtpVerification.d.ts.map +1 -1
  25. package/dist/components/auth/OtpVerification.js +11 -5
  26. package/dist/components/auth/OtpVerification.js.map +1 -1
  27. package/dist/components/auth/OtpVerification.mjs +24 -17
  28. package/dist/components/auth/OtpVerification.mjs.map +1 -1
  29. package/dist/components/auth/constants.d.ts +6 -1
  30. package/dist/components/auth/constants.d.ts.map +1 -1
  31. package/dist/components/auth/constants.js +6 -0
  32. package/dist/components/auth/constants.js.map +1 -1
  33. package/dist/components/auth/constants.mjs +6 -0
  34. package/dist/components/auth/constants.mjs.map +1 -1
  35. package/dist/contexts/TurnkeyContext.d.ts.map +1 -1
  36. package/dist/contexts/TurnkeyContext.js +24 -16
  37. package/dist/contexts/TurnkeyContext.js.map +1 -1
  38. package/dist/contexts/TurnkeyContext.mjs +30 -33
  39. package/dist/contexts/TurnkeyContext.mjs.map +1 -1
  40. package/dist/hooks/use-session.d.ts.map +1 -1
  41. package/dist/hooks/use-session.js +24 -12
  42. package/dist/hooks/use-session.js.map +1 -1
  43. package/dist/hooks/use-session.mjs +28 -14
  44. package/dist/hooks/use-session.mjs.map +1 -1
  45. package/dist/index.js +1 -1
  46. package/package.json +4 -4
@@ -1,6 +1,8 @@
1
1
  'use client';
2
2
  'use strict';
3
3
 
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
4
6
  var jsxRuntime = require('react/jsx-runtime');
5
7
  var Auth_module = require('./Auth.module.css.js');
6
8
  var React = require('react');
@@ -20,6 +22,11 @@ var constants = require('./constants.js');
20
22
  var sdkServer = require('@turnkey/sdk-server');
21
23
  var parsePhoneNumberFromString = require('libphonenumber-js');
22
24
 
25
+ exports.SessionType = void 0;
26
+ (function (SessionType) {
27
+ SessionType["READ_ONLY"] = "SESSION_TYPE_READ_ONLY";
28
+ SessionType["READ_WRITE"] = "SESSION_TYPE_READ_WRITE";
29
+ })(exports.SessionType || (exports.SessionType = {}));
23
30
  const passkeyIcon = jsxRuntime.jsxs("svg", {
24
31
  xmlns: "http://www.w3.org/2000/svg",
25
32
  width: "43",
@@ -27,14 +34,14 @@ const passkeyIcon = jsxRuntime.jsxs("svg", {
27
34
  fill: "none",
28
35
  children: [jsxRuntime.jsx("path", {
29
36
  fill: "var(--icon-color)",
30
- "fill-rule": "evenodd",
37
+ fillRule: "evenodd",
31
38
  d: "M27.52 37.06a6.8 6.8 0 0 0-2.02-.31H12a6.75 6.75 0 0 0-6.75 6.75V48H.75v-4.5A11.25 11.25 0 0 1 12 32.25h13.5c.68 0 1.355.062 2.016.182zm4.698-23.74a13.5 13.5 0 1 0-8.503 13.484c-.057-.178-.131-.425-.167-.566a13 13 0 0 1-.229-1.134 12 12 0 0 1-.054-.448q-.02-.202-.013-1.064c.007-.82.01-.877.055-1.186.018-.121.046-.29.072-.438a9 9 0 1 1 4.315-6.714 13.83 13.83 0 0 1 .87-.564 14 14 0 0 1 1.08-.556c.102-.045.299-.128.44-.184.14-.056.384-.146.544-.202.16-.055.436-.141.615-.194.18-.05.467-.125.641-.165.092-.02.214-.046.334-.07",
32
- "clip-rule": "evenodd"
39
+ clipRule: "evenodd"
33
40
  }), jsxRuntime.jsx("path", {
34
41
  fill: "var(--icon-color)",
35
- "fill-rule": "evenodd",
42
+ fillRule: "evenodd",
36
43
  d: "M33.844 16.554a9.563 9.563 0 0 0-.975.134c-.125.022-.355.075-.51.114s-.418.12-.589.177a11 11 0 0 0-.553.21 12 12 0 0 0-.519.244 8.29 8.29 0 0 0-.961.573c-.114.08-.313.23-.445.334-.13.104-.358.31-.507.454a10 10 0 0 0-.466.495c-.107.127-.269.334-.362.46-.091.128-.232.34-.313.474-.079.133-.195.34-.256.46-.062.122-.15.308-.196.413a10 10 0 0 0-.152.387c-.04.107-.1.304-.14.44a9 9 0 0 0-.119.51c-.028.145-.065.374-.082.51a6 6 0 0 0-.032.773c-.002.327.007.598.021.712a8.924 8.924 0 0 0 .163.905c.03.116.09.322.134.457.046.136.125.35.178.475a8 8 0 0 0 .725 1.329 9.15 9.15 0 0 0 .622.772c.111.121.294.306.408.41.114.101.295.256.4.342.108.085.273.211.37.28.097.068.244.165.325.218l.299.179c.082.047.251.137.374.2.125.062.232.127.24.146.013.025.018 2.403.018 7.032 0 5.905.004 7.018.025 7.125.014.07.047.18.075.24.029.064.08.156.113.203.032.05.522.654 1.086 1.345.564.693 1.07 1.31 1.123 1.371.054.063.14.151.195.195.054.042.162.111.239.151s.204.092.281.115c.121.035.181.04.413.04.206 0 .3-.007.387-.03a2 2 0 0 0 .237-.09 1.8 1.8 0 0 0 .388-.25c.029-.029.547-.657 1.153-1.397a97 97 0 0 0 1.12-1.383.4.4 0 0 0 .019-.137c0-.053-.016-.178-.035-.276a5 5 0 0 0-.273-.876 24 24 0 0 0-.298-.73 32 32 0 0 0-.626-1.365.8.8 0 0 1-.069-.172q.001-.033.041-.043c.021-.003.134-.016.25-.026s.295-.032.395-.046c.102-.016.248-.044.325-.065a.9.9 0 0 0 .237-.102.8.8 0 0 0 .15-.133c.028-.037.073-.116.1-.174.026-.058.054-.16.065-.229a1.895 1.895 0 0 0-.042-.589 2 2 0 0 0-.074-.193c-.023-.053-.355-.542-.736-1.085-.38-.543-.693-1.005-.693-1.025 0-.028.037-.046.234-.105.128-.04.339-.113.469-.162.132-.047.293-.116.36-.15a1 1 0 0 0 .204-.144.8.8 0 0 0 .144-.212c.034-.072.072-.18.085-.238s.024-.2.024-.316c0-.123-.009-.25-.024-.308a1.4 1.4 0 0 0-.072-.202c-.032-.07-.275-.39-.737-.975-.378-.479-.687-.883-.687-.9s.018-.043.04-.055.197-.11.39-.215c.194-.103.431-.237.528-.295.096-.058.22-.15.274-.204a1.1 1.1 0 0 0 .257-.459c.026-.1.031-.247.04-1.283.005-.642.016-1.178.023-1.19s.105-.069.22-.125c.112-.058.284-.15.38-.204a10 10 0 0 0 .985-.668 6.762 6.762 0 0 0 .826-.767c.107-.117.267-.305.358-.418a8 8 0 0 0 .605-.891 8.9 8.9 0 0 0 .373-.756c.045-.105.12-.308.17-.448a8 8 0 0 0 .156-.536c.037-.155.088-.408.113-.563.023-.155.05-.381.061-.505a8 8 0 0 0-.007-1.139 8 8 0 0 0-.07-.527 8 8 0 0 0-.097-.466c-.028-.116-.08-.3-.116-.413a7 7 0 0 0-.83-1.714 10 10 0 0 0-.256-.37 9 9 0 0 0-.23-.29 9 9 0 0 0-.81-.82 9 9 0 0 0-.395-.32 9 9 0 0 0-.835-.556 13 13 0 0 0-.417-.221 11 11 0 0 0-.483-.223 8 8 0 0 0-.98-.343 11 11 0 0 0-.422-.108c-.106-.022-.288-.06-.404-.079a10 10 0 0 0-.51-.073 8 8 0 0 0-.852-.043c-.304-.001-.644.002-.756.011m.207 3.334-.058.006a4.6 4.6 0 0 0-1.283.341 4 4 0 0 0-.334.159 4.354 4.354 0 0 0-.668.452 5.5 5.5 0 0 0-.669.69 5 5 0 0 0-.207.308 4 4 0 0 0-.18.325c-.04.088-.101.234-.135.325a3.856 3.856 0 0 0-.177.66c-.016.087-.034.24-.04.342-.01.159-.008.19.017.215.028.03.25.031 4.175.031 3.663 0 4.15-.003 4.174-.026q.029-.027.028-.12a3 3 0 0 0-.072-.574 3.9 3.9 0 0 0-.297-.87 4 4 0 0 0-.21-.379 6 6 0 0 0-.23-.316 6 6 0 0 0-.346-.37 5 5 0 0 0-.365-.326 7 7 0 0 0-.246-.178 5 5 0 0 0-.264-.16 4.6 4.6 0 0 0-1.585-.52 5.681 5.681 0 0 0-.84-.035z",
37
- "clip-rule": "evenodd"
44
+ clipRule: "evenodd"
38
45
  })]
39
46
  });
40
47
  const passkeyIconError = jsxRuntime.jsxs("svg", {
@@ -44,14 +51,14 @@ const passkeyIconError = jsxRuntime.jsxs("svg", {
44
51
  fill: "none",
45
52
  children: [jsxRuntime.jsx("path", {
46
53
  fill: "var(--error-color)",
47
- "fill-rule": "evenodd",
54
+ fillRule: "evenodd",
48
55
  d: "M27.52 37.06a6.8 6.8 0 0 0-2.02-.31H12a6.75 6.75 0 0 0-6.75 6.75V48H.75v-4.5A11.25 11.25 0 0 1 12 32.25h13.5c.68 0 1.355.062 2.016.182zm4.698-23.74a13.5 13.5 0 1 0-8.503 13.484c-.057-.178-.131-.425-.167-.566a13 13 0 0 1-.229-1.134 12 12 0 0 1-.054-.448q-.02-.202-.013-1.064c.007-.82.01-.877.055-1.186.018-.121.046-.29.072-.438a9 9 0 1 1 4.315-6.714 13.83 13.83 0 0 1 .87-.564 14 14 0 0 1 1.08-.556c.102-.045.299-.128.44-.184.14-.056.384-.146.544-.202.16-.055.436-.141.615-.194.18-.05.467-.125.641-.165.092-.02.214-.046.334-.07",
49
- "clip-rule": "evenodd"
56
+ clipRule: "evenodd"
50
57
  }), jsxRuntime.jsx("path", {
51
58
  fill: "var(--error-color)",
52
- "fill-rule": "evenodd",
59
+ fillRule: "evenodd",
53
60
  d: "M33.844 16.554a9.563 9.563 0 0 0-.975.134c-.125.022-.355.075-.51.114s-.418.12-.589.177a11 11 0 0 0-.553.21 12 12 0 0 0-.519.244 8.29 8.29 0 0 0-.961.573c-.114.08-.313.23-.445.334-.13.104-.358.31-.507.454a10 10 0 0 0-.466.495c-.107.127-.269.334-.362.46-.091.128-.232.34-.313.474-.079.133-.195.34-.256.46-.062.122-.15.308-.196.413a10 10 0 0 0-.152.387c-.04.107-.1.304-.14.44a9 9 0 0 0-.119.51c-.028.145-.065.374-.082.51a6 6 0 0 0-.032.773c-.002.327.007.598.021.712a8.924 8.924 0 0 0 .163.905c.03.116.09.322.134.457.046.136.125.35.178.475a8 8 0 0 0 .725 1.329 9.15 9.15 0 0 0 .622.772c.111.121.294.306.408.41.114.101.295.256.4.342.108.085.273.211.37.28.097.068.244.165.325.218l.299.179c.082.047.251.137.374.2.125.062.232.127.24.146.013.025.018 2.403.018 7.032 0 5.905.004 7.018.025 7.125.014.07.047.18.075.24.029.064.08.156.113.203.032.05.522.654 1.086 1.345.564.693 1.07 1.31 1.123 1.371.054.063.14.151.195.195.054.042.162.111.239.151s.204.092.281.115c.121.035.181.04.413.04.206 0 .3-.007.387-.03a2 2 0 0 0 .237-.09 1.8 1.8 0 0 0 .388-.25c.029-.029.547-.657 1.153-1.397a97 97 0 0 0 1.12-1.383.4.4 0 0 0 .019-.137c0-.053-.016-.178-.035-.276a5 5 0 0 0-.273-.876 24 24 0 0 0-.298-.73 32 32 0 0 0-.626-1.365.8.8 0 0 1-.069-.172q.001-.033.041-.043c.021-.003.134-.016.25-.026s.295-.032.395-.046c.102-.016.248-.044.325-.065a.9.9 0 0 0 .237-.102.8.8 0 0 0 .15-.133c.028-.037.073-.116.1-.174.026-.058.054-.16.065-.229a1.895 1.895 0 0 0-.042-.589 2 2 0 0 0-.074-.193c-.023-.053-.355-.542-.736-1.085-.38-.543-.693-1.005-.693-1.025 0-.028.037-.046.234-.105.128-.04.339-.113.469-.162.132-.047.293-.116.36-.15a1 1 0 0 0 .204-.144.8.8 0 0 0 .144-.212c.034-.072.072-.18.085-.238s.024-.2.024-.316c0-.123-.009-.25-.024-.308a1.4 1.4 0 0 0-.072-.202c-.032-.07-.275-.39-.737-.975-.378-.479-.687-.883-.687-.9s.018-.043.04-.055.197-.11.39-.215c.194-.103.431-.237.528-.295.096-.058.22-.15.274-.204a1.1 1.1 0 0 0 .257-.459c.026-.1.031-.247.04-1.283.005-.642.016-1.178.023-1.19s.105-.069.22-.125c.112-.058.284-.15.38-.204a10 10 0 0 0 .985-.668 6.762 6.762 0 0 0 .826-.767c.107-.117.267-.305.358-.418a8 8 0 0 0 .605-.891 8.9 8.9 0 0 0 .373-.756c.045-.105.12-.308.17-.448a8 8 0 0 0 .156-.536c.037-.155.088-.408.113-.563.023-.155.05-.381.061-.505a8 8 0 0 0-.007-1.139 8 8 0 0 0-.07-.527 8 8 0 0 0-.097-.466c-.028-.116-.08-.3-.116-.413a7 7 0 0 0-.83-1.714 10 10 0 0 0-.256-.37 9 9 0 0 0-.23-.29 9 9 0 0 0-.81-.82 9 9 0 0 0-.395-.32 9 9 0 0 0-.835-.556 13 13 0 0 0-.417-.221 11 11 0 0 0-.483-.223 8 8 0 0 0-.98-.343 11 11 0 0 0-.422-.108c-.106-.022-.288-.06-.404-.079a10 10 0 0 0-.51-.073 8 8 0 0 0-.852-.043c-.304-.001-.644.002-.756.011m.207 3.334-.058.006a4.6 4.6 0 0 0-1.283.341 4 4 0 0 0-.334.159 4.354 4.354 0 0 0-.668.452 5.5 5.5 0 0 0-.669.69 5 5 0 0 0-.207.308 4 4 0 0 0-.18.325c-.04.088-.101.234-.135.325a3.856 3.856 0 0 0-.177.66c-.016.087-.034.24-.04.342-.01.159-.008.19.017.215.028.03.25.031 4.175.031 3.663 0 4.15-.003 4.174-.026q.029-.027.028-.12a3 3 0 0 0-.072-.574 3.9 3.9 0 0 0-.297-.87 4 4 0 0 0-.21-.379 6 6 0 0 0-.23-.316 6 6 0 0 0-.346-.37 5 5 0 0 0-.365-.326 7 7 0 0 0-.246-.178 5 5 0 0 0-.264-.16 4.6 4.6 0 0 0-1.585-.52 5.681 5.681 0 0 0-.84-.035z",
54
- "clip-rule": "evenodd"
61
+ clipRule: "evenodd"
55
62
  })]
56
63
  });
57
64
  const Auth = ({
@@ -59,24 +66,27 @@ const Auth = ({
59
66
  onError,
60
67
  authConfig,
61
68
  configOrder,
69
+ emailCustomization,
70
+ sendFromEmailAddress,
62
71
  customSmsMessage,
63
72
  customAccounts
64
73
  }) => {
65
74
  const {
66
- passkeyClient,
67
75
  authIframeClient,
68
- turnkey: turnkey$1
76
+ passkeyClient,
77
+ walletClient
69
78
  } = useTurnkey.useTurnkey();
70
79
  const [email, setEmail] = React.useState("");
71
80
  const [phone, setPhone] = React.useState("");
72
81
  const [otpId, setOtpId] = React.useState(null);
73
82
  const [step, setStep] = React.useState("auth");
83
+ const [loading, setLoading] = React.useState();
74
84
  const [oauthLoading, setOauthLoading] = React.useState("");
75
85
  const [suborgId, setSuborgId] = React.useState("");
76
86
  const [passkeySignupScreen, setPasskeySignupScreen] = React.useState(false);
77
87
  const [passkeyCreationScreen, setPasskeyCreationScreen] = React.useState(false);
78
88
  const [passkeySignupError, setPasskeySignupError] = React.useState("");
79
- const [loading, setLoading] = React.useState(true);
89
+ const [componentReady, setComponentReady] = React.useState(false);
80
90
  const [passkeyCreated, setPasskeyCreated] = React.useState(false);
81
91
  const handleResendCode = async () => {
82
92
  if (step === constants.OtpType.Email) {
@@ -87,10 +97,10 @@ const Auth = ({
87
97
  };
88
98
  React.useEffect(() => {
89
99
  if (authIframeClient) {
90
- setLoading(false);
100
+ setComponentReady(true);
91
101
  }
92
102
  }, [authIframeClient]);
93
- if (loading) {
103
+ if (!componentReady) {
94
104
  return jsxRuntime.jsx("div", {
95
105
  className: Auth_module.defaultLoader,
96
106
  children: jsxRuntime.jsx(material.CircularProgress, {
@@ -105,13 +115,6 @@ const Auth = ({
105
115
  const phoneNumber = parsePhoneNumberFromString(phone);
106
116
  return phoneNumber?.isValid() ?? false;
107
117
  };
108
- const handleAuthSuccess = async (credentialBundle, expirationSeconds) => {
109
- if (credentialBundle) {
110
- await authIframeClient.injectCredentialBundle(credentialBundle);
111
- await authIframeClient.loginWithAuthBundle(credentialBundle, expirationSeconds);
112
- await onAuthSuccess();
113
- }
114
- };
115
118
  const handleSignupWithPasskey = async () => {
116
119
  setPasskeySignupError("");
117
120
  const siteInfo = `${new URL(window.location.href).hostname} - ${new Date().toLocaleString(undefined, {
@@ -158,41 +161,27 @@ const Auth = ({
158
161
  constants.authErrors.passkey.createFailed;
159
162
  }
160
163
  }
161
- const sessionResponse = await passkeyClient?.createReadWriteSession({
162
- targetPublicKey: authIframeClient?.iframePublicKey,
163
- ...(authConfig.sessionLengthSeconds !== undefined && {
164
- expirationSeconds: authConfig.sessionLengthSeconds.toString()
165
- }),
166
- organizationId: turnkey$1?.config.defaultOrganizationId ?? process.env.NEXT_PUBLIC_ORGANIZATION_ID
167
- });
168
- if (sessionResponse?.credentialBundle) {
169
- await handleAuthSuccess(sessionResponse.credentialBundle, authConfig.sessionLengthSeconds?.toString());
170
- } else {
171
- setPasskeySignupError(constants.authErrors.passkey.loginFailed);
172
- }
173
- } catch {
164
+ await passkeyClient?.loginWithPasskey(exports.SessionType.READ_WRITE, authIframeClient, authIframeClient?.iframePublicKey, authConfig.sessionLengthSeconds?.toString());
165
+ await onAuthSuccess();
166
+ } catch (error) {
174
167
  setPasskeySignupError(constants.authErrors.passkey.timeoutOrNotAllowed);
168
+ console.error("Error during passkey signup: ", error);
175
169
  }
176
170
  };
177
171
  const handleLoginWithPasskey = async () => {
178
172
  try {
179
- const sessionResponse = await passkeyClient?.createReadWriteSession({
180
- targetPublicKey: authIframeClient?.iframePublicKey,
181
- ...(authConfig.sessionLengthSeconds !== undefined && {
182
- expirationSeconds: authConfig.sessionLengthSeconds.toString()
183
- }),
184
- organizationId: turnkey$1?.config.defaultOrganizationId ?? process.env.NEXT_PUBLIC_ORGANIZATION_ID
185
- });
186
- if (sessionResponse?.credentialBundle) {
187
- await handleAuthSuccess(sessionResponse.credentialBundle, authConfig.sessionLengthSeconds?.toString());
188
- } else {
189
- constants.authErrors.passkey.loginFailed;
190
- }
173
+ setLoading("passkey");
174
+ await passkeyClient?.loginWithPasskey(exports.SessionType.READ_WRITE, authIframeClient, authIframeClient?.iframePublicKey, authConfig.sessionLengthSeconds?.toString());
175
+ await onAuthSuccess();
191
176
  } catch (error) {
192
177
  onError(constants.authErrors.passkey.loginFailed);
178
+ console.error("Error during passkey login: ", error);
179
+ } finally {
180
+ setLoading(undefined);
193
181
  }
194
182
  };
195
183
  const handleOtpLogin = async (type, value, otpType) => {
184
+ setLoading(otpType);
196
185
  const createSuborgData = {};
197
186
  if (type === constants.FilterType.Email) createSuborgData.email = value;else if (type === constants.FilterType.PhoneNumber) createSuborgData.phoneNumber = value;
198
187
  if (customAccounts) {
@@ -213,6 +202,12 @@ const Auth = ({
213
202
  suborgID: suborgId,
214
203
  otpType,
215
204
  contact: value,
205
+ ...(emailCustomization && {
206
+ emailCustomization
207
+ }),
208
+ ...(sendFromEmailAddress && {
209
+ sendFromEmailAddress
210
+ }),
216
211
  ...(customSmsMessage && {
217
212
  customSmsMessage
218
213
  }),
@@ -225,6 +220,7 @@ const Auth = ({
225
220
  } else {
226
221
  onError(constants.authErrors.otp.sendFailed);
227
222
  }
223
+ setLoading(undefined);
228
224
  };
229
225
  const handleOAuthLogin = async (credential, providerName) => {
230
226
  setOauthLoading(providerName);
@@ -248,18 +244,56 @@ const Auth = ({
248
244
  return;
249
245
  }
250
246
  const suborgId = suborgIds[0];
251
- const oauthResponse = await sdkServer.server.oauth({
247
+ const oauthSession = await sdkServer.server.oauth({
252
248
  suborgID: suborgId,
253
249
  oidcToken: credential,
254
250
  targetPublicKey: authIframeClient?.iframePublicKey,
255
251
  sessionLengthSeconds: authConfig.sessionLengthSeconds
256
252
  });
257
- if (oauthResponse && oauthResponse.token) {
258
- await handleAuthSuccess(oauthResponse.token, authConfig.sessionLengthSeconds?.toString());
253
+ if (oauthSession && oauthSession.token) {
254
+ await authIframeClient.loginWithSession(oauthSession);
255
+ await onAuthSuccess();
259
256
  } else {
260
257
  onError(constants.authErrors.oauth.loginFailed);
261
258
  }
262
259
  };
260
+ const handleLoginWithWallet = async () => {
261
+ setLoading("wallet");
262
+ try {
263
+ if (!walletClient) {
264
+ throw new Error("Wallet client not initialized");
265
+ }
266
+ const publicKey = await walletClient.getPublicKey();
267
+ if (!publicKey) {
268
+ throw new Error(constants.authErrors.wallet.noPublicKey);
269
+ }
270
+ const {
271
+ type
272
+ } = walletClient.getWalletInterface();
273
+ const resp = await sdkServer.server.getOrCreateSuborg({
274
+ filterType: constants.FilterType.PublicKey,
275
+ filterValue: publicKey,
276
+ additionalData: {
277
+ wallet: {
278
+ publicKey,
279
+ type
280
+ }
281
+ }
282
+ });
283
+ const suborgIds = resp?.subOrganizationIds;
284
+ if (!suborgIds || suborgIds.length === 0) {
285
+ onError(constants.authErrors.wallet.loginFailed);
286
+ return;
287
+ }
288
+ await walletClient.loginWithWallet(exports.SessionType.READ_WRITE, authIframeClient, authIframeClient?.iframePublicKey, authConfig.sessionLengthSeconds?.toString());
289
+ await onAuthSuccess();
290
+ } catch (error) {
291
+ onError(error.message || constants.authErrors.wallet.loginFailed);
292
+ console.error("Error during wallet login: ", error);
293
+ } finally {
294
+ setLoading(undefined);
295
+ }
296
+ };
263
297
  const renderBackButton = () => jsxRuntime.jsx(ChevronLeftIcon, {
264
298
  onClick: () => {
265
299
  setPasskeyCreationScreen(false);
@@ -348,8 +382,12 @@ const Auth = ({
348
382
  }), jsxRuntime.jsx("button", {
349
383
  className: Auth_module.authButton,
350
384
  type: "submit",
351
- disabled: !isValidEmail(email),
352
- children: "Continue"
385
+ disabled: !isValidEmail(email) || loading === constants.OtpType.Email,
386
+ children: loading === constants.OtpType.Email ? jsxRuntime.jsx(material.CircularProgress, {
387
+ size: 24,
388
+ thickness: 4,
389
+ className: Auth_module.buttonProgress || ""
390
+ }) : "Continue"
353
391
  })]
354
392
  }) : null;
355
393
  case "phone":
@@ -367,8 +405,12 @@ const Auth = ({
367
405
  }), jsxRuntime.jsx("button", {
368
406
  className: Auth_module.authButton,
369
407
  type: "submit",
370
- disabled: !isValidPhone(phone),
371
- children: "Continue"
408
+ disabled: !isValidPhone(phone) || loading === constants.OtpType.Sms,
409
+ children: loading === constants.OtpType.Sms ? jsxRuntime.jsx(material.CircularProgress, {
410
+ size: 24,
411
+ thickness: 4,
412
+ className: Auth_module.buttonProgress || ""
413
+ }) : "Continue"
372
414
  })]
373
415
  }) : null;
374
416
  case "passkey":
@@ -378,13 +420,33 @@ const Auth = ({
378
420
  className: Auth_module.authButton,
379
421
  type: "button",
380
422
  onClick: handleLoginWithPasskey,
381
- children: "Log in with passkey"
423
+ disabled: loading === "passkey",
424
+ children: loading === "passkey" ? jsxRuntime.jsx(material.CircularProgress, {
425
+ size: 24,
426
+ thickness: 4,
427
+ className: Auth_module.buttonProgress || ""
428
+ }) : "Log in with passkey"
382
429
  }), jsxRuntime.jsx("div", {
383
430
  className: Auth_module.noPasskeyLink,
384
431
  onClick: () => setPasskeySignupScreen(true),
385
432
  children: "Sign up with passkey"
386
433
  })]
387
434
  }) : null;
435
+ case "wallet":
436
+ return authConfig.walletEnabled && !otpId ? jsxRuntime.jsx("div", {
437
+ className: Auth_module.passkeyContainer,
438
+ children: jsxRuntime.jsx("button", {
439
+ className: Auth_module.authButton,
440
+ type: "button",
441
+ onClick: handleLoginWithWallet,
442
+ disabled: loading === "wallet",
443
+ children: loading === "wallet" ? jsxRuntime.jsx(material.CircularProgress, {
444
+ size: 24,
445
+ thickness: 4,
446
+ className: Auth_module.buttonProgress || ""
447
+ }) : "Continue with Wallet"
448
+ })
449
+ }) : null;
388
450
  case "socials":
389
451
  return authConfig.googleEnabled || authConfig.appleEnabled || authConfig.facebookEnabled ? renderSocialButtons() : null;
390
452
  default:
@@ -499,8 +561,7 @@ const Auth = ({
499
561
  suborgId: suborgId,
500
562
  otpId: otpId,
501
563
  sessionLengthSeconds: authConfig.sessionLengthSeconds,
502
- authIframeClient: authIframeClient,
503
- onValidateSuccess: handleAuthSuccess,
564
+ onValidateSuccess: onAuthSuccess,
504
565
  onResendCode: handleResendCode
505
566
  }), !otpId && jsxRuntime.jsx("div", {
506
567
  className: Auth_module.tos,
@@ -534,5 +595,5 @@ const Auth = ({
534
595
  });
535
596
  };
536
597
 
537
- module.exports = Auth;
598
+ exports.default = Auth;
538
599
  //# sourceMappingURL=Auth.js.map