@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
@@ -19,6 +19,11 @@ import { OtpType, FilterType, authErrors } from './constants.mjs';
19
19
  import { server } from '@turnkey/sdk-server';
20
20
  import parsePhoneNumberFromString from 'libphonenumber-js';
21
21
 
22
+ var SessionType;
23
+ (function (SessionType) {
24
+ SessionType["READ_ONLY"] = "SESSION_TYPE_READ_ONLY";
25
+ SessionType["READ_WRITE"] = "SESSION_TYPE_READ_WRITE";
26
+ })(SessionType || (SessionType = {}));
22
27
  var passkeyIcon = jsxs("svg", {
23
28
  xmlns: "http://www.w3.org/2000/svg",
24
29
  width: "43",
@@ -26,14 +31,14 @@ var passkeyIcon = jsxs("svg", {
26
31
  fill: "none",
27
32
  children: [jsx("path", {
28
33
  fill: "var(--icon-color)",
29
- "fill-rule": "evenodd",
34
+ fillRule: "evenodd",
30
35
  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",
31
- "clip-rule": "evenodd"
36
+ clipRule: "evenodd"
32
37
  }), jsx("path", {
33
38
  fill: "var(--icon-color)",
34
- "fill-rule": "evenodd",
39
+ fillRule: "evenodd",
35
40
  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",
36
- "clip-rule": "evenodd"
41
+ clipRule: "evenodd"
37
42
  })]
38
43
  });
39
44
  var passkeyIconError = jsxs("svg", {
@@ -43,14 +48,14 @@ var passkeyIconError = jsxs("svg", {
43
48
  fill: "none",
44
49
  children: [jsx("path", {
45
50
  fill: "var(--error-color)",
46
- "fill-rule": "evenodd",
51
+ fillRule: "evenodd",
47
52
  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",
48
- "clip-rule": "evenodd"
53
+ clipRule: "evenodd"
49
54
  }), jsx("path", {
50
55
  fill: "var(--error-color)",
51
- "fill-rule": "evenodd",
56
+ fillRule: "evenodd",
52
57
  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",
53
- "clip-rule": "evenodd"
58
+ clipRule: "evenodd"
54
59
  })]
55
60
  });
56
61
  var Auth = function Auth(_ref) {
@@ -58,12 +63,14 @@ var Auth = function Auth(_ref) {
58
63
  onError = _ref.onError,
59
64
  authConfig = _ref.authConfig,
60
65
  configOrder = _ref.configOrder,
66
+ emailCustomization = _ref.emailCustomization,
67
+ sendFromEmailAddress = _ref.sendFromEmailAddress,
61
68
  customSmsMessage = _ref.customSmsMessage,
62
69
  customAccounts = _ref.customAccounts;
63
70
  var _useTurnkey = useTurnkey(),
64
- passkeyClient = _useTurnkey.passkeyClient,
65
71
  authIframeClient = _useTurnkey.authIframeClient,
66
- turnkey = _useTurnkey.turnkey;
72
+ passkeyClient = _useTurnkey.passkeyClient,
73
+ walletClient = _useTurnkey.walletClient;
67
74
  var _useState = useState(""),
68
75
  _useState2 = _slicedToArray(_useState, 2),
69
76
  email = _useState2[0],
@@ -80,34 +87,38 @@ var Auth = function Auth(_ref) {
80
87
  _useState8 = _slicedToArray(_useState7, 2),
81
88
  step = _useState8[0],
82
89
  setStep = _useState8[1];
83
- var _useState9 = useState(""),
90
+ var _useState9 = useState(),
84
91
  _useState10 = _slicedToArray(_useState9, 2),
85
- oauthLoading = _useState10[0],
86
- setOauthLoading = _useState10[1];
92
+ loading = _useState10[0],
93
+ setLoading = _useState10[1];
87
94
  var _useState11 = useState(""),
88
95
  _useState12 = _slicedToArray(_useState11, 2),
89
- suborgId = _useState12[0],
90
- setSuborgId = _useState12[1];
91
- var _useState13 = useState(false),
96
+ oauthLoading = _useState12[0],
97
+ setOauthLoading = _useState12[1];
98
+ var _useState13 = useState(""),
92
99
  _useState14 = _slicedToArray(_useState13, 2),
93
- passkeySignupScreen = _useState14[0],
94
- setPasskeySignupScreen = _useState14[1];
100
+ suborgId = _useState14[0],
101
+ setSuborgId = _useState14[1];
95
102
  var _useState15 = useState(false),
96
103
  _useState16 = _slicedToArray(_useState15, 2),
97
- passkeyCreationScreen = _useState16[0],
98
- setPasskeyCreationScreen = _useState16[1];
99
- var _useState17 = useState(""),
104
+ passkeySignupScreen = _useState16[0],
105
+ setPasskeySignupScreen = _useState16[1];
106
+ var _useState17 = useState(false),
100
107
  _useState18 = _slicedToArray(_useState17, 2),
101
- passkeySignupError = _useState18[0],
102
- setPasskeySignupError = _useState18[1];
103
- var _useState19 = useState(true),
108
+ passkeyCreationScreen = _useState18[0],
109
+ setPasskeyCreationScreen = _useState18[1];
110
+ var _useState19 = useState(""),
104
111
  _useState20 = _slicedToArray(_useState19, 2),
105
- loading = _useState20[0],
106
- setLoading = _useState20[1];
112
+ passkeySignupError = _useState20[0],
113
+ setPasskeySignupError = _useState20[1];
107
114
  var _useState21 = useState(false),
108
115
  _useState22 = _slicedToArray(_useState21, 2),
109
- passkeyCreated = _useState22[0],
110
- setPasskeyCreated = _useState22[1];
116
+ componentReady = _useState22[0],
117
+ setComponentReady = _useState22[1];
118
+ var _useState23 = useState(false),
119
+ _useState24 = _slicedToArray(_useState23, 2),
120
+ passkeyCreated = _useState24[0],
121
+ setPasskeyCreated = _useState24[1];
111
122
  var handleResendCode = /*#__PURE__*/function () {
112
123
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
113
124
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -141,10 +152,10 @@ var Auth = function Auth(_ref) {
141
152
  }();
142
153
  useEffect(function () {
143
154
  if (authIframeClient) {
144
- setLoading(false);
155
+ setComponentReady(true);
145
156
  }
146
157
  }, [authIframeClient]);
147
- if (loading) {
158
+ if (!componentReady) {
148
159
  return jsx("div", {
149
160
  className: styles.defaultLoader,
150
161
  children: jsx(CircularProgress, {
@@ -162,38 +173,11 @@ var Auth = function Auth(_ref) {
162
173
  var phoneNumber = parsePhoneNumberFromString(phone);
163
174
  return (_phoneNumber$isValid = phoneNumber === null || phoneNumber === void 0 ? void 0 : phoneNumber.isValid()) !== null && _phoneNumber$isValid !== void 0 ? _phoneNumber$isValid : false;
164
175
  };
165
- var handleAuthSuccess = /*#__PURE__*/function () {
166
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(credentialBundle, expirationSeconds) {
176
+ var handleSignupWithPasskey = /*#__PURE__*/function () {
177
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
178
+ var siteInfo, _authConfig$sessionLe, _ref4, encodedChallenge, attestation, response;
167
179
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
168
180
  while (1) switch (_context2.prev = _context2.next) {
169
- case 0:
170
- if (!credentialBundle) {
171
- _context2.next = 7;
172
- break;
173
- }
174
- _context2.next = 3;
175
- return authIframeClient.injectCredentialBundle(credentialBundle);
176
- case 3:
177
- _context2.next = 5;
178
- return authIframeClient.loginWithAuthBundle(credentialBundle, expirationSeconds);
179
- case 5:
180
- _context2.next = 7;
181
- return onAuthSuccess();
182
- case 7:
183
- case "end":
184
- return _context2.stop();
185
- }
186
- }, _callee2);
187
- }));
188
- return function handleAuthSuccess(_x, _x2) {
189
- return _ref3.apply(this, arguments);
190
- };
191
- }();
192
- var handleSignupWithPasskey = /*#__PURE__*/function () {
193
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
194
- var siteInfo, _turnkey$config$defau, _ref5, encodedChallenge, attestation, response, sessionResponse, _authConfig$sessionLe;
195
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
196
- while (1) switch (_context3.prev = _context3.next) {
197
181
  case 0:
198
182
  setPasskeySignupError("");
199
183
  siteInfo = "".concat(new URL(window.location.href).hostname, " - ").concat(new Date().toLocaleString(undefined, {
@@ -206,12 +190,12 @@ var Auth = function Auth(_ref) {
206
190
  }));
207
191
  setPasskeySignupScreen(false);
208
192
  setPasskeyCreationScreen(true);
209
- _context3.prev = 4;
193
+ _context2.prev = 4;
210
194
  if (passkeyCreated) {
211
- _context3.next = 22;
195
+ _context2.next = 22;
212
196
  break;
213
197
  }
214
- _context3.next = 8;
198
+ _context2.next = 8;
215
199
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.createUserPasskey({
216
200
  publicKey: {
217
201
  user: {
@@ -221,21 +205,21 @@ var Auth = function Auth(_ref) {
221
205
  }
222
206
  });
223
207
  case 8:
224
- _context3.t0 = _context3.sent;
225
- if (_context3.t0) {
226
- _context3.next = 11;
208
+ _context2.t0 = _context2.sent;
209
+ if (_context2.t0) {
210
+ _context2.next = 11;
227
211
  break;
228
212
  }
229
- _context3.t0 = {};
213
+ _context2.t0 = {};
230
214
  case 11:
231
- _ref5 = _context3.t0;
232
- encodedChallenge = _ref5.encodedChallenge;
233
- attestation = _ref5.attestation;
215
+ _ref4 = _context2.t0;
216
+ encodedChallenge = _ref4.encodedChallenge;
217
+ attestation = _ref4.attestation;
234
218
  if (!(encodedChallenge && attestation)) {
235
- _context3.next = 21;
219
+ _context2.next = 21;
236
220
  break;
237
221
  }
238
- _context3.next = 17;
222
+ _context2.next = 17;
239
223
  return server.createSuborg(_objectSpread2({
240
224
  email: email,
241
225
  passkey: {
@@ -247,136 +231,117 @@ var Auth = function Auth(_ref) {
247
231
  customAccounts: customAccounts
248
232
  }));
249
233
  case 17:
250
- response = _context3.sent;
234
+ response = _context2.sent;
251
235
  if (response !== null && response !== void 0 && response.subOrganizationId) {
252
236
  setPasskeyCreated(true);
253
237
  }
254
- _context3.next = 22;
238
+ _context2.next = 22;
255
239
  break;
256
240
  case 21:
257
241
  case 22:
258
- _context3.next = 24;
259
- return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.createReadWriteSession(_objectSpread2(_objectSpread2({
260
- targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey
261
- }, authConfig.sessionLengthSeconds !== undefined && {
262
- expirationSeconds: authConfig.sessionLengthSeconds.toString()
263
- }), {}, {
264
- organizationId: (_turnkey$config$defau = turnkey === null || turnkey === void 0 ? void 0 : turnkey.config.defaultOrganizationId) !== null && _turnkey$config$defau !== void 0 ? _turnkey$config$defau : process.env.NEXT_PUBLIC_ORGANIZATION_ID
265
- }));
242
+ _context2.next = 24;
243
+ return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.loginWithPasskey(SessionType.READ_WRITE, authIframeClient, authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey, (_authConfig$sessionLe = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe === void 0 ? void 0 : _authConfig$sessionLe.toString());
266
244
  case 24:
267
- sessionResponse = _context3.sent;
268
- if (!(sessionResponse !== null && sessionResponse !== void 0 && sessionResponse.credentialBundle)) {
269
- _context3.next = 30;
270
- break;
271
- }
272
- _context3.next = 28;
273
- return handleAuthSuccess(sessionResponse.credentialBundle, (_authConfig$sessionLe = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe === void 0 ? void 0 : _authConfig$sessionLe.toString());
274
- case 28:
275
- _context3.next = 31;
276
- break;
277
- case 30:
278
- setPasskeySignupError(authErrors.passkey.loginFailed);
279
- case 31:
280
- _context3.next = 36;
245
+ _context2.next = 26;
246
+ return onAuthSuccess();
247
+ case 26:
248
+ _context2.next = 32;
281
249
  break;
282
- case 33:
283
- _context3.prev = 33;
284
- _context3.t1 = _context3["catch"](4);
250
+ case 28:
251
+ _context2.prev = 28;
252
+ _context2.t1 = _context2["catch"](4);
285
253
  setPasskeySignupError(authErrors.passkey.timeoutOrNotAllowed);
286
- case 36:
254
+ console.error("Error during passkey signup: ", _context2.t1);
255
+ case 32:
287
256
  case "end":
288
- return _context3.stop();
257
+ return _context2.stop();
289
258
  }
290
- }, _callee3, null, [[4, 33]]);
259
+ }, _callee2, null, [[4, 28]]);
291
260
  }));
292
261
  return function handleSignupWithPasskey() {
293
- return _ref4.apply(this, arguments);
262
+ return _ref3.apply(this, arguments);
294
263
  };
295
264
  }();
296
265
  var handleLoginWithPasskey = /*#__PURE__*/function () {
297
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
298
- var _turnkey$config$defau2, sessionResponse, _authConfig$sessionLe2;
299
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
300
- while (1) switch (_context4.prev = _context4.next) {
266
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
267
+ var _authConfig$sessionLe2;
268
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
269
+ while (1) switch (_context3.prev = _context3.next) {
301
270
  case 0:
302
- _context4.prev = 0;
303
- _context4.next = 3;
304
- return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.createReadWriteSession(_objectSpread2(_objectSpread2({
305
- targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey
306
- }, authConfig.sessionLengthSeconds !== undefined && {
307
- expirationSeconds: authConfig.sessionLengthSeconds.toString()
308
- }), {}, {
309
- organizationId: (_turnkey$config$defau2 = turnkey === null || turnkey === void 0 ? void 0 : turnkey.config.defaultOrganizationId) !== null && _turnkey$config$defau2 !== void 0 ? _turnkey$config$defau2 : process.env.NEXT_PUBLIC_ORGANIZATION_ID
310
- }));
311
- case 3:
312
- sessionResponse = _context4.sent;
313
- if (!(sessionResponse !== null && sessionResponse !== void 0 && sessionResponse.credentialBundle)) {
314
- _context4.next = 9;
315
- break;
316
- }
317
- _context4.next = 7;
318
- return handleAuthSuccess(sessionResponse.credentialBundle, (_authConfig$sessionLe2 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe2 === void 0 ? void 0 : _authConfig$sessionLe2.toString());
319
- case 7:
320
- _context4.next = 10;
321
- break;
322
- case 9:
323
- case 10:
324
- _context4.next = 15;
271
+ _context3.prev = 0;
272
+ setLoading("passkey");
273
+ _context3.next = 4;
274
+ return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.loginWithPasskey(SessionType.READ_WRITE, authIframeClient, authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey, (_authConfig$sessionLe2 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe2 === void 0 ? void 0 : _authConfig$sessionLe2.toString());
275
+ case 4:
276
+ _context3.next = 6;
277
+ return onAuthSuccess();
278
+ case 6:
279
+ _context3.next = 12;
325
280
  break;
326
- case 12:
327
- _context4.prev = 12;
328
- _context4.t0 = _context4["catch"](0);
281
+ case 8:
282
+ _context3.prev = 8;
283
+ _context3.t0 = _context3["catch"](0);
329
284
  onError(authErrors.passkey.loginFailed);
285
+ console.error("Error during passkey login: ", _context3.t0);
286
+ case 12:
287
+ _context3.prev = 12;
288
+ setLoading(undefined);
289
+ return _context3.finish(12);
330
290
  case 15:
331
291
  case "end":
332
- return _context4.stop();
292
+ return _context3.stop();
333
293
  }
334
- }, _callee4, null, [[0, 12]]);
294
+ }, _callee3, null, [[0, 8, 12, 15]]);
335
295
  }));
336
296
  return function handleLoginWithPasskey() {
337
- return _ref6.apply(this, arguments);
297
+ return _ref5.apply(this, arguments);
338
298
  };
339
299
  }();
340
300
  var handleOtpLogin = /*#__PURE__*/function () {
341
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(type, value, otpType) {
301
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(type, value, otpType) {
342
302
  var createSuborgData, resp, suborgIds, suborgId, initAuthResponse;
343
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
344
- while (1) switch (_context5.prev = _context5.next) {
303
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
304
+ while (1) switch (_context4.prev = _context4.next) {
345
305
  case 0:
306
+ setLoading(otpType);
346
307
  createSuborgData = {};
347
308
  if (type === FilterType.Email) createSuborgData.email = value;else if (type === FilterType.PhoneNumber) createSuborgData.phoneNumber = value;
348
309
  if (customAccounts) {
349
310
  createSuborgData.customAccounts = customAccounts;
350
311
  }
351
- _context5.next = 5;
312
+ _context4.next = 6;
352
313
  return server.getOrCreateSuborg({
353
314
  filterType: type,
354
315
  filterValue: value,
355
316
  additionalData: createSuborgData
356
317
  });
357
- case 5:
358
- resp = _context5.sent;
318
+ case 6:
319
+ resp = _context4.sent;
359
320
  suborgIds = resp === null || resp === void 0 ? void 0 : resp.subOrganizationIds;
360
321
  if (!(!suborgIds || suborgIds.length === 0)) {
361
- _context5.next = 10;
322
+ _context4.next = 11;
362
323
  break;
363
324
  }
364
325
  onError(authErrors.otp.sendFailed);
365
- return _context5.abrupt("return");
366
- case 10:
326
+ return _context4.abrupt("return");
327
+ case 11:
367
328
  suborgId = suborgIds[0];
368
- _context5.next = 13;
369
- return server.sendOtp(_objectSpread2(_objectSpread2({
329
+ _context4.next = 14;
330
+ return server.sendOtp(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
370
331
  suborgID: suborgId,
371
332
  otpType: otpType,
372
333
  contact: value
373
- }, customSmsMessage && {
334
+ }, emailCustomization && {
335
+ emailCustomization: emailCustomization
336
+ }), sendFromEmailAddress && {
337
+ sendFromEmailAddress: sendFromEmailAddress
338
+ }), customSmsMessage && {
374
339
  customSmsMessage: customSmsMessage
375
340
  }), {}, {
376
341
  userIdentifier: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey
377
342
  }));
378
- case 13:
379
- initAuthResponse = _context5.sent;
343
+ case 14:
344
+ initAuthResponse = _context4.sent;
380
345
  if (initAuthResponse && initAuthResponse.otpId) {
381
346
  setSuborgId(suborgId);
382
347
  setOtpId(initAuthResponse === null || initAuthResponse === void 0 ? void 0 : initAuthResponse.otpId);
@@ -384,21 +349,22 @@ var Auth = function Auth(_ref) {
384
349
  } else {
385
350
  onError(authErrors.otp.sendFailed);
386
351
  }
387
- case 15:
352
+ setLoading(undefined);
353
+ case 17:
388
354
  case "end":
389
- return _context5.stop();
355
+ return _context4.stop();
390
356
  }
391
- }, _callee5);
357
+ }, _callee4);
392
358
  }));
393
- return function handleOtpLogin(_x3, _x4, _x5) {
394
- return _ref7.apply(this, arguments);
359
+ return function handleOtpLogin(_x, _x2, _x3) {
360
+ return _ref6.apply(this, arguments);
395
361
  };
396
362
  }();
397
363
  var handleOAuthLogin = /*#__PURE__*/function () {
398
- var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(credential, providerName) {
399
- var createSuborgData, resp, suborgIds, suborgId, oauthResponse, _authConfig$sessionLe3;
400
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
401
- while (1) switch (_context6.prev = _context6.next) {
364
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(credential, providerName) {
365
+ var createSuborgData, resp, suborgIds, suborgId, oauthSession;
366
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
367
+ while (1) switch (_context5.prev = _context5.next) {
402
368
  case 0:
403
369
  setOauthLoading(providerName);
404
370
  createSuborgData = {
@@ -410,24 +376,24 @@ var Auth = function Auth(_ref) {
410
376
  if (customAccounts) {
411
377
  createSuborgData.customAccounts = customAccounts;
412
378
  }
413
- _context6.next = 5;
379
+ _context5.next = 5;
414
380
  return server.getOrCreateSuborg({
415
381
  filterType: FilterType.OidcToken,
416
382
  filterValue: credential,
417
383
  additionalData: createSuborgData
418
384
  });
419
385
  case 5:
420
- resp = _context6.sent;
386
+ resp = _context5.sent;
421
387
  suborgIds = resp === null || resp === void 0 ? void 0 : resp.subOrganizationIds;
422
388
  if (!(!suborgIds || suborgIds.length === 0)) {
423
- _context6.next = 10;
389
+ _context5.next = 10;
424
390
  break;
425
391
  }
426
392
  onError(authErrors.oauth.loginFailed);
427
- return _context6.abrupt("return");
393
+ return _context5.abrupt("return");
428
394
  case 10:
429
395
  suborgId = suborgIds[0];
430
- _context6.next = 13;
396
+ _context5.next = 13;
431
397
  return server.oauth({
432
398
  suborgID: suborgId,
433
399
  oidcToken: credential,
@@ -435,25 +401,101 @@ var Auth = function Auth(_ref) {
435
401
  sessionLengthSeconds: authConfig.sessionLengthSeconds
436
402
  });
437
403
  case 13:
438
- oauthResponse = _context6.sent;
439
- if (!(oauthResponse && oauthResponse.token)) {
440
- _context6.next = 19;
404
+ oauthSession = _context5.sent;
405
+ if (!(oauthSession && oauthSession.token)) {
406
+ _context5.next = 21;
441
407
  break;
442
408
  }
443
- _context6.next = 17;
444
- return handleAuthSuccess(oauthResponse.token, (_authConfig$sessionLe3 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe3 === void 0 ? void 0 : _authConfig$sessionLe3.toString());
409
+ _context5.next = 17;
410
+ return authIframeClient.loginWithSession(oauthSession);
445
411
  case 17:
446
- _context6.next = 20;
447
- break;
412
+ _context5.next = 19;
413
+ return onAuthSuccess();
448
414
  case 19:
415
+ _context5.next = 22;
416
+ break;
417
+ case 21:
449
418
  onError(authErrors.oauth.loginFailed);
450
- case 20:
419
+ case 22:
420
+ case "end":
421
+ return _context5.stop();
422
+ }
423
+ }, _callee5);
424
+ }));
425
+ return function handleOAuthLogin(_x4, _x5) {
426
+ return _ref7.apply(this, arguments);
427
+ };
428
+ }();
429
+ var handleLoginWithWallet = /*#__PURE__*/function () {
430
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
431
+ var _authConfig$sessionLe3, publicKey, _walletClient$getWall, type, resp, suborgIds;
432
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
433
+ while (1) switch (_context6.prev = _context6.next) {
434
+ case 0:
435
+ setLoading("wallet");
436
+ _context6.prev = 1;
437
+ if (walletClient) {
438
+ _context6.next = 4;
439
+ break;
440
+ }
441
+ throw new Error("Wallet client not initialized");
442
+ case 4:
443
+ _context6.next = 6;
444
+ return walletClient.getPublicKey();
445
+ case 6:
446
+ publicKey = _context6.sent;
447
+ if (publicKey) {
448
+ _context6.next = 9;
449
+ break;
450
+ }
451
+ throw new Error(authErrors.wallet.noPublicKey);
452
+ case 9:
453
+ _walletClient$getWall = walletClient.getWalletInterface(), type = _walletClient$getWall.type;
454
+ _context6.next = 12;
455
+ return server.getOrCreateSuborg({
456
+ filterType: FilterType.PublicKey,
457
+ filterValue: publicKey,
458
+ additionalData: {
459
+ wallet: {
460
+ publicKey: publicKey,
461
+ type: type
462
+ }
463
+ }
464
+ });
465
+ case 12:
466
+ resp = _context6.sent;
467
+ suborgIds = resp === null || resp === void 0 ? void 0 : resp.subOrganizationIds;
468
+ if (!(!suborgIds || suborgIds.length === 0)) {
469
+ _context6.next = 17;
470
+ break;
471
+ }
472
+ onError(authErrors.wallet.loginFailed);
473
+ return _context6.abrupt("return");
474
+ case 17:
475
+ _context6.next = 19;
476
+ return walletClient.loginWithWallet(SessionType.READ_WRITE, authIframeClient, authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey, (_authConfig$sessionLe3 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe3 === void 0 ? void 0 : _authConfig$sessionLe3.toString());
477
+ case 19:
478
+ _context6.next = 21;
479
+ return onAuthSuccess();
480
+ case 21:
481
+ _context6.next = 27;
482
+ break;
483
+ case 23:
484
+ _context6.prev = 23;
485
+ _context6.t0 = _context6["catch"](1);
486
+ onError(_context6.t0.message || authErrors.wallet.loginFailed);
487
+ console.error("Error during wallet login: ", _context6.t0);
488
+ case 27:
489
+ _context6.prev = 27;
490
+ setLoading(undefined);
491
+ return _context6.finish(27);
492
+ case 30:
451
493
  case "end":
452
494
  return _context6.stop();
453
495
  }
454
- }, _callee6);
496
+ }, _callee6, null, [[1, 23, 27, 30]]);
455
497
  }));
456
- return function handleOAuthLogin(_x6, _x7) {
498
+ return function handleLoginWithWallet() {
457
499
  return _ref8.apply(this, arguments);
458
500
  };
459
501
  }();
@@ -554,8 +596,12 @@ var Auth = function Auth(_ref) {
554
596
  }), jsx("button", {
555
597
  className: styles.authButton,
556
598
  type: "submit",
557
- disabled: !isValidEmail(email),
558
- children: "Continue"
599
+ disabled: !isValidEmail(email) || loading === OtpType.Email,
600
+ children: loading === OtpType.Email ? jsx(CircularProgress, {
601
+ size: 24,
602
+ thickness: 4,
603
+ className: styles.buttonProgress || ""
604
+ }) : "Continue"
559
605
  })]
560
606
  }) : null;
561
607
  case "phone":
@@ -575,8 +621,12 @@ var Auth = function Auth(_ref) {
575
621
  }), jsx("button", {
576
622
  className: styles.authButton,
577
623
  type: "submit",
578
- disabled: !isValidPhone(phone),
579
- children: "Continue"
624
+ disabled: !isValidPhone(phone) || loading === OtpType.Sms,
625
+ children: loading === OtpType.Sms ? jsx(CircularProgress, {
626
+ size: 24,
627
+ thickness: 4,
628
+ className: styles.buttonProgress || ""
629
+ }) : "Continue"
580
630
  })]
581
631
  }) : null;
582
632
  case "passkey":
@@ -586,7 +636,12 @@ var Auth = function Auth(_ref) {
586
636
  className: styles.authButton,
587
637
  type: "button",
588
638
  onClick: handleLoginWithPasskey,
589
- children: "Log in with passkey"
639
+ disabled: loading === "passkey",
640
+ children: loading === "passkey" ? jsx(CircularProgress, {
641
+ size: 24,
642
+ thickness: 4,
643
+ className: styles.buttonProgress || ""
644
+ }) : "Log in with passkey"
590
645
  }), jsx("div", {
591
646
  className: styles.noPasskeyLink,
592
647
  onClick: function onClick() {
@@ -595,6 +650,21 @@ var Auth = function Auth(_ref) {
595
650
  children: "Sign up with passkey"
596
651
  })]
597
652
  }) : null;
653
+ case "wallet":
654
+ return authConfig.walletEnabled && !otpId ? jsx("div", {
655
+ className: styles.passkeyContainer,
656
+ children: jsx("button", {
657
+ className: styles.authButton,
658
+ type: "button",
659
+ onClick: handleLoginWithWallet,
660
+ disabled: loading === "wallet",
661
+ children: loading === "wallet" ? jsx(CircularProgress, {
662
+ size: 24,
663
+ thickness: 4,
664
+ className: styles.buttonProgress || ""
665
+ }) : "Continue with Wallet"
666
+ })
667
+ }) : null;
598
668
  case "socials":
599
669
  return authConfig.googleEnabled || authConfig.appleEnabled || authConfig.facebookEnabled ? renderSocialButtons() : null;
600
670
  default:
@@ -713,8 +783,7 @@ var Auth = function Auth(_ref) {
713
783
  suborgId: suborgId,
714
784
  otpId: otpId,
715
785
  sessionLengthSeconds: authConfig.sessionLengthSeconds,
716
- authIframeClient: authIframeClient,
717
- onValidateSuccess: handleAuthSuccess,
786
+ onValidateSuccess: onAuthSuccess,
718
787
  onResendCode: handleResendCode
719
788
  }), !otpId && jsx("div", {
720
789
  className: styles.tos,
@@ -750,5 +819,5 @@ var Auth = function Auth(_ref) {
750
819
  });
751
820
  };
752
821
 
753
- export { Auth as default };
822
+ export { SessionType, Auth as default };
754
823
  //# sourceMappingURL=Auth.mjs.map