@turnkey/sdk-react 3.1.0 → 4.1.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 (40) hide show
  1. package/CHANGELOG.md +100 -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 +7 -1
  8. package/dist/components/auth/Auth.d.ts.map +1 -1
  9. package/dist/components/auth/Auth.js +81 -71
  10. package/dist/components/auth/Auth.js.map +1 -1
  11. package/dist/components/auth/Auth.mjs +213 -238
  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/contexts/TurnkeyContext.d.ts.map +1 -1
  30. package/dist/contexts/TurnkeyContext.js +24 -16
  31. package/dist/contexts/TurnkeyContext.js.map +1 -1
  32. package/dist/contexts/TurnkeyContext.mjs +30 -33
  33. package/dist/contexts/TurnkeyContext.mjs.map +1 -1
  34. package/dist/hooks/use-session.d.ts.map +1 -1
  35. package/dist/hooks/use-session.js +24 -12
  36. package/dist/hooks/use-session.js.map +1 -1
  37. package/dist/hooks/use-session.mjs +28 -14
  38. package/dist/hooks/use-session.mjs.map +1 -1
  39. package/dist/index.js +1 -1
  40. package/package.json +5 -5
@@ -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,27 +66,28 @@ 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
- walletClient,
69
- turnkey: turnkey$1
76
+ passkeyClient,
77
+ walletClient
70
78
  } = useTurnkey.useTurnkey();
71
79
  const [email, setEmail] = React.useState("");
72
80
  const [phone, setPhone] = React.useState("");
73
81
  const [otpId, setOtpId] = React.useState(null);
74
82
  const [step, setStep] = React.useState("auth");
83
+ const [loading, setLoading] = React.useState();
75
84
  const [oauthLoading, setOauthLoading] = React.useState("");
76
85
  const [suborgId, setSuborgId] = React.useState("");
77
86
  const [passkeySignupScreen, setPasskeySignupScreen] = React.useState(false);
78
87
  const [passkeyCreationScreen, setPasskeyCreationScreen] = React.useState(false);
79
88
  const [passkeySignupError, setPasskeySignupError] = React.useState("");
80
- const [loading, setLoading] = React.useState(true);
89
+ const [componentReady, setComponentReady] = React.useState(false);
81
90
  const [passkeyCreated, setPasskeyCreated] = React.useState(false);
82
- const [walletLoading, setWalletLoading] = React.useState(false);
83
91
  const handleResendCode = async () => {
84
92
  if (step === constants.OtpType.Email) {
85
93
  await handleOtpLogin(constants.FilterType.Email, email, constants.OtpType.Email);
@@ -89,10 +97,10 @@ const Auth = ({
89
97
  };
90
98
  React.useEffect(() => {
91
99
  if (authIframeClient) {
92
- setLoading(false);
100
+ setComponentReady(true);
93
101
  }
94
102
  }, [authIframeClient]);
95
- if (loading) {
103
+ if (!componentReady) {
96
104
  return jsxRuntime.jsx("div", {
97
105
  className: Auth_module.defaultLoader,
98
106
  children: jsxRuntime.jsx(material.CircularProgress, {
@@ -107,13 +115,6 @@ const Auth = ({
107
115
  const phoneNumber = parsePhoneNumberFromString(phone);
108
116
  return phoneNumber?.isValid() ?? false;
109
117
  };
110
- const handleAuthSuccess = async (credentialBundle, expirationSeconds) => {
111
- if (credentialBundle) {
112
- await authIframeClient.injectCredentialBundle(credentialBundle);
113
- await authIframeClient.loginWithAuthBundle(credentialBundle, expirationSeconds);
114
- await onAuthSuccess();
115
- }
116
- };
117
118
  const handleSignupWithPasskey = async () => {
118
119
  setPasskeySignupError("");
119
120
  const siteInfo = `${new URL(window.location.href).hostname} - ${new Date().toLocaleString(undefined, {
@@ -160,41 +161,37 @@ const Auth = ({
160
161
  constants.authErrors.passkey.createFailed;
161
162
  }
162
163
  }
163
- const sessionResponse = await passkeyClient?.createReadWriteSession({
164
+ await passkeyClient?.loginWithPasskey({
165
+ sessionType: exports.SessionType.READ_WRITE,
166
+ iframeClient: authIframeClient,
164
167
  targetPublicKey: authIframeClient?.iframePublicKey,
165
- ...(authConfig.sessionLengthSeconds !== undefined && {
166
- expirationSeconds: authConfig.sessionLengthSeconds.toString()
167
- }),
168
- organizationId: turnkey$1?.config.defaultOrganizationId ?? process.env.NEXT_PUBLIC_ORGANIZATION_ID
168
+ expirationSeconds: authConfig.sessionLengthSeconds?.toString()
169
169
  });
170
- if (sessionResponse?.credentialBundle) {
171
- await handleAuthSuccess(sessionResponse.credentialBundle, authConfig.sessionLengthSeconds?.toString());
172
- } else {
173
- setPasskeySignupError(constants.authErrors.passkey.loginFailed);
174
- }
175
- } catch {
170
+ await onAuthSuccess();
171
+ } catch (error) {
176
172
  setPasskeySignupError(constants.authErrors.passkey.timeoutOrNotAllowed);
173
+ console.error("Error during passkey signup: ", error);
177
174
  }
178
175
  };
179
176
  const handleLoginWithPasskey = async () => {
180
177
  try {
181
- const sessionResponse = await passkeyClient?.createReadWriteSession({
178
+ setLoading("passkey");
179
+ await passkeyClient?.loginWithPasskey({
180
+ sessionType: exports.SessionType.READ_WRITE,
181
+ iframeClient: authIframeClient,
182
182
  targetPublicKey: authIframeClient?.iframePublicKey,
183
- ...(authConfig.sessionLengthSeconds !== undefined && {
184
- expirationSeconds: authConfig.sessionLengthSeconds.toString()
185
- }),
186
- organizationId: turnkey$1?.config.defaultOrganizationId ?? process.env.NEXT_PUBLIC_ORGANIZATION_ID
183
+ expirationSeconds: authConfig.sessionLengthSeconds?.toString()
187
184
  });
188
- if (sessionResponse?.credentialBundle) {
189
- await handleAuthSuccess(sessionResponse.credentialBundle, authConfig.sessionLengthSeconds?.toString());
190
- } else {
191
- constants.authErrors.passkey.loginFailed;
192
- }
185
+ await onAuthSuccess();
193
186
  } catch (error) {
194
187
  onError(constants.authErrors.passkey.loginFailed);
188
+ console.error("Error during passkey login: ", error);
189
+ } finally {
190
+ setLoading(undefined);
195
191
  }
196
192
  };
197
193
  const handleOtpLogin = async (type, value, otpType) => {
194
+ setLoading(otpType);
198
195
  const createSuborgData = {};
199
196
  if (type === constants.FilterType.Email) createSuborgData.email = value;else if (type === constants.FilterType.PhoneNumber) createSuborgData.phoneNumber = value;
200
197
  if (customAccounts) {
@@ -215,6 +212,12 @@ const Auth = ({
215
212
  suborgID: suborgId,
216
213
  otpType,
217
214
  contact: value,
215
+ ...(emailCustomization && {
216
+ emailCustomization
217
+ }),
218
+ ...(sendFromEmailAddress && {
219
+ sendFromEmailAddress
220
+ }),
218
221
  ...(customSmsMessage && {
219
222
  customSmsMessage
220
223
  }),
@@ -227,6 +230,7 @@ const Auth = ({
227
230
  } else {
228
231
  onError(constants.authErrors.otp.sendFailed);
229
232
  }
233
+ setLoading(undefined);
230
234
  };
231
235
  const handleOAuthLogin = async (credential, providerName) => {
232
236
  setOauthLoading(providerName);
@@ -250,20 +254,21 @@ const Auth = ({
250
254
  return;
251
255
  }
252
256
  const suborgId = suborgIds[0];
253
- const oauthResponse = await sdkServer.server.oauth({
257
+ const oauthSession = await sdkServer.server.oauth({
254
258
  suborgID: suborgId,
255
259
  oidcToken: credential,
256
260
  targetPublicKey: authIframeClient?.iframePublicKey,
257
261
  sessionLengthSeconds: authConfig.sessionLengthSeconds
258
262
  });
259
- if (oauthResponse && oauthResponse.token) {
260
- await handleAuthSuccess(oauthResponse.token, authConfig.sessionLengthSeconds?.toString());
263
+ if (oauthSession && oauthSession.token) {
264
+ await authIframeClient.loginWithSession(oauthSession);
265
+ await onAuthSuccess();
261
266
  } else {
262
267
  onError(constants.authErrors.oauth.loginFailed);
263
268
  }
264
269
  };
265
270
  const handleLoginWithWallet = async () => {
266
- setWalletLoading(true);
271
+ setLoading("wallet");
267
272
  try {
268
273
  if (!walletClient) {
269
274
  throw new Error("Wallet client not initialized");
@@ -290,25 +295,18 @@ const Auth = ({
290
295
  onError(constants.authErrors.wallet.loginFailed);
291
296
  return;
292
297
  }
293
- const suborgId = suborgIds[0];
294
- const sessionResponse = await walletClient.createReadWriteSession({
298
+ await walletClient.loginWithWallet({
299
+ sessionType: exports.SessionType.READ_WRITE,
300
+ iframeClient: authIframeClient,
295
301
  targetPublicKey: authIframeClient?.iframePublicKey,
296
- ...(suborgId && {
297
- organizationId: suborgId
298
- }),
299
- ...(authConfig.sessionLengthSeconds !== undefined && {
300
- expirationSeconds: authConfig.sessionLengthSeconds.toString()
301
- })
302
+ expirationSeconds: authConfig.sessionLengthSeconds?.toString()
302
303
  });
303
- if (sessionResponse?.credentialBundle) {
304
- await handleAuthSuccess(sessionResponse.credentialBundle, authConfig.sessionLengthSeconds?.toString());
305
- } else {
306
- throw new Error(constants.authErrors.wallet.loginFailed);
307
- }
304
+ await onAuthSuccess();
308
305
  } catch (error) {
309
306
  onError(error.message || constants.authErrors.wallet.loginFailed);
307
+ console.error("Error during wallet login: ", error);
310
308
  } finally {
311
- setWalletLoading(false);
309
+ setLoading(undefined);
312
310
  }
313
311
  };
314
312
  const renderBackButton = () => jsxRuntime.jsx(ChevronLeftIcon, {
@@ -399,8 +397,12 @@ const Auth = ({
399
397
  }), jsxRuntime.jsx("button", {
400
398
  className: Auth_module.authButton,
401
399
  type: "submit",
402
- disabled: !isValidEmail(email),
403
- children: "Continue"
400
+ disabled: !isValidEmail(email) || loading === constants.OtpType.Email,
401
+ children: loading === constants.OtpType.Email ? jsxRuntime.jsx(material.CircularProgress, {
402
+ size: 24,
403
+ thickness: 4,
404
+ className: Auth_module.buttonProgress || ""
405
+ }) : "Continue"
404
406
  })]
405
407
  }) : null;
406
408
  case "phone":
@@ -418,8 +420,12 @@ const Auth = ({
418
420
  }), jsxRuntime.jsx("button", {
419
421
  className: Auth_module.authButton,
420
422
  type: "submit",
421
- disabled: !isValidPhone(phone),
422
- children: "Continue"
423
+ disabled: !isValidPhone(phone) || loading === constants.OtpType.Sms,
424
+ children: loading === constants.OtpType.Sms ? jsxRuntime.jsx(material.CircularProgress, {
425
+ size: 24,
426
+ thickness: 4,
427
+ className: Auth_module.buttonProgress || ""
428
+ }) : "Continue"
423
429
  })]
424
430
  }) : null;
425
431
  case "passkey":
@@ -429,7 +435,12 @@ const Auth = ({
429
435
  className: Auth_module.authButton,
430
436
  type: "button",
431
437
  onClick: handleLoginWithPasskey,
432
- children: "Log in with passkey"
438
+ disabled: loading === "passkey",
439
+ children: loading === "passkey" ? jsxRuntime.jsx(material.CircularProgress, {
440
+ size: 24,
441
+ thickness: 4,
442
+ className: Auth_module.buttonProgress || ""
443
+ }) : "Log in with passkey"
433
444
  }), jsxRuntime.jsx("div", {
434
445
  className: Auth_module.noPasskeyLink,
435
446
  onClick: () => setPasskeySignupScreen(true),
@@ -443,8 +454,8 @@ const Auth = ({
443
454
  className: Auth_module.authButton,
444
455
  type: "button",
445
456
  onClick: handleLoginWithWallet,
446
- disabled: walletLoading,
447
- children: walletLoading ? jsxRuntime.jsx(material.CircularProgress, {
457
+ disabled: loading === "wallet",
458
+ children: loading === "wallet" ? jsxRuntime.jsx(material.CircularProgress, {
448
459
  size: 24,
449
460
  thickness: 4,
450
461
  className: Auth_module.buttonProgress || ""
@@ -565,8 +576,7 @@ const Auth = ({
565
576
  suborgId: suborgId,
566
577
  otpId: otpId,
567
578
  sessionLengthSeconds: authConfig.sessionLengthSeconds,
568
- authIframeClient: authIframeClient,
569
- onValidateSuccess: handleAuthSuccess,
579
+ onValidateSuccess: onAuthSuccess,
570
580
  onResendCode: handleResendCode
571
581
  }), !otpId && jsxRuntime.jsx("div", {
572
582
  className: Auth_module.tos,
@@ -600,5 +610,5 @@ const Auth = ({
600
610
  });
601
611
  };
602
612
 
603
- module.exports = Auth;
613
+ exports.default = Auth;
604
614
  //# sourceMappingURL=Auth.js.map