@turnkey/sdk-react 5.0.0 → 5.0.2

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 (34) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/components/auth/Apple.d.ts +0 -1
  3. package/dist/components/auth/Apple.d.ts.map +1 -1
  4. package/dist/components/auth/Apple.js +62 -48
  5. package/dist/components/auth/Apple.js.map +1 -1
  6. package/dist/components/auth/Apple.mjs +104 -53
  7. package/dist/components/auth/Apple.mjs.map +1 -1
  8. package/dist/components/auth/Auth.d.ts.map +1 -1
  9. package/dist/components/auth/Auth.js +18 -19
  10. package/dist/components/auth/Auth.js.map +1 -1
  11. package/dist/components/auth/Auth.mjs +135 -137
  12. package/dist/components/auth/Auth.mjs.map +1 -1
  13. package/dist/components/auth/Facebook.d.ts +0 -1
  14. package/dist/components/auth/Facebook.d.ts.map +1 -1
  15. package/dist/components/auth/Facebook.js +80 -44
  16. package/dist/components/auth/Facebook.js.map +1 -1
  17. package/dist/components/auth/Facebook.mjs +155 -104
  18. package/dist/components/auth/Facebook.mjs.map +1 -1
  19. package/dist/components/auth/Google.d.ts +0 -1
  20. package/dist/components/auth/Google.d.ts.map +1 -1
  21. package/dist/components/auth/Google.js +70 -52
  22. package/dist/components/auth/Google.js.map +1 -1
  23. package/dist/components/auth/Google.mjs +116 -80
  24. package/dist/components/auth/Google.mjs.map +1 -1
  25. package/dist/components/auth/OtpVerification.d.ts.map +1 -1
  26. package/dist/components/auth/OtpVerification.js +1 -0
  27. package/dist/components/auth/OtpVerification.js.map +1 -1
  28. package/dist/components/auth/OtpVerification.mjs +30 -27
  29. package/dist/components/auth/OtpVerification.mjs.map +1 -1
  30. package/dist/components/auth/constants.js +1 -1
  31. package/dist/components/auth/constants.js.map +1 -1
  32. package/dist/components/auth/constants.mjs +1 -1
  33. package/dist/components/auth/constants.mjs.map +1 -1
  34. package/package.json +1 -1
@@ -77,52 +77,48 @@ var Auth = function Auth(_ref) {
77
77
  turnkey = _useTurnkey.turnkey;
78
78
  var _useState = useState(""),
79
79
  _useState2 = _slicedToArray(_useState, 2),
80
- publicKey = _useState2[0],
81
- setPublicKey = _useState2[1];
80
+ email = _useState2[0],
81
+ setEmail = _useState2[1];
82
82
  var _useState3 = useState(""),
83
83
  _useState4 = _slicedToArray(_useState3, 2),
84
- email = _useState4[0],
85
- setEmail = _useState4[1];
86
- var _useState5 = useState(""),
84
+ phone = _useState4[0],
85
+ setPhone = _useState4[1];
86
+ var _useState5 = useState(null),
87
87
  _useState6 = _slicedToArray(_useState5, 2),
88
- phone = _useState6[0],
89
- setPhone = _useState6[1];
90
- var _useState7 = useState(null),
88
+ otpId = _useState6[0],
89
+ setOtpId = _useState6[1];
90
+ var _useState7 = useState("auth"),
91
91
  _useState8 = _slicedToArray(_useState7, 2),
92
- otpId = _useState8[0],
93
- setOtpId = _useState8[1];
94
- var _useState9 = useState("auth"),
92
+ step = _useState8[0],
93
+ setStep = _useState8[1];
94
+ var _useState9 = useState(),
95
95
  _useState10 = _slicedToArray(_useState9, 2),
96
- step = _useState10[0],
97
- setStep = _useState10[1];
98
- var _useState11 = useState(),
96
+ loading = _useState10[0],
97
+ setLoading = _useState10[1];
98
+ var _useState11 = useState(""),
99
99
  _useState12 = _slicedToArray(_useState11, 2),
100
- loading = _useState12[0],
101
- setLoading = _useState12[1];
102
- var _useState13 = useState(""),
100
+ oauthLoading = _useState12[0],
101
+ setOauthLoading = _useState12[1];
102
+ var _useState13 = useState(false),
103
103
  _useState14 = _slicedToArray(_useState13, 2),
104
- oauthLoading = _useState14[0],
105
- setOauthLoading = _useState14[1];
104
+ passkeySignupScreen = _useState14[0],
105
+ setPasskeySignupScreen = _useState14[1];
106
106
  var _useState15 = useState(false),
107
107
  _useState16 = _slicedToArray(_useState15, 2),
108
- passkeySignupScreen = _useState16[0],
109
- setPasskeySignupScreen = _useState16[1];
110
- var _useState17 = useState(false),
108
+ passkeyCreationScreen = _useState16[0],
109
+ setPasskeyCreationScreen = _useState16[1];
110
+ var _useState17 = useState(""),
111
111
  _useState18 = _slicedToArray(_useState17, 2),
112
- passkeyCreationScreen = _useState18[0],
113
- setPasskeyCreationScreen = _useState18[1];
114
- var _useState19 = useState(""),
112
+ passkeySignupError = _useState18[0],
113
+ setPasskeySignupError = _useState18[1];
114
+ var _useState19 = useState(false),
115
115
  _useState20 = _slicedToArray(_useState19, 2),
116
- passkeySignupError = _useState20[0],
117
- setPasskeySignupError = _useState20[1];
116
+ componentReady = _useState20[0],
117
+ setComponentReady = _useState20[1];
118
118
  var _useState21 = useState(false),
119
119
  _useState22 = _slicedToArray(_useState21, 2),
120
- componentReady = _useState22[0],
121
- setComponentReady = _useState22[1];
122
- var _useState23 = useState(false),
123
- _useState24 = _slicedToArray(_useState23, 2),
124
- passkeyCreated = _useState24[0],
125
- setPasskeyCreated = _useState24[1];
120
+ passkeyCreated = _useState22[0],
121
+ setPasskeyCreated = _useState22[1];
126
122
  var handleResendCode = /*#__PURE__*/function () {
127
123
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
128
124
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -155,51 +151,37 @@ var Auth = function Auth(_ref) {
155
151
  };
156
152
  }();
157
153
  useEffect(function () {
158
- if (indexedDbClient && turnkey) {
159
- setComponentReady(true);
160
- var manageClient = /*#__PURE__*/function () {
161
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
162
- var session, _publicKey, _publicKey2;
163
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
164
- while (1) switch (_context2.prev = _context2.next) {
165
- case 0:
166
- _context2.next = 2;
167
- return turnkey.getSession();
168
- case 2:
169
- session = _context2.sent;
170
- if (!session) {
171
- _context2.next = 10;
172
- break;
173
- }
174
- _context2.next = 6;
175
- return indexedDbClient.getPublicKey();
176
- case 6:
177
- _publicKey = _context2.sent;
178
- setPublicKey(_publicKey);
179
- _context2.next = 16;
154
+ var manageClient = /*#__PURE__*/function () {
155
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
156
+ var retrievedPublicKey;
157
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
158
+ while (1) switch (_context2.prev = _context2.next) {
159
+ case 0:
160
+ if (!(indexedDbClient && turnkey)) {
161
+ _context2.next = 5;
180
162
  break;
181
- case 10:
182
- _context2.next = 12;
183
- return indexedDbClient.resetKeyPair();
184
- case 12:
185
- _context2.next = 14;
186
- return indexedDbClient.getPublicKey();
187
- case 14:
188
- _publicKey2 = _context2.sent;
189
- setPublicKey(_publicKey2);
190
- case 16:
191
- case "end":
192
- return _context2.stop();
193
- }
194
- }, _callee2);
195
- }));
196
- return function manageClient() {
197
- return _ref3.apply(this, arguments);
198
- };
199
- }();
200
- manageClient();
201
- }
202
- }, [indexedDbClient]);
163
+ }
164
+ _context2.next = 3;
165
+ return indexedDbClient.getPublicKey();
166
+ case 3:
167
+ retrievedPublicKey = _context2.sent;
168
+ if (retrievedPublicKey) {
169
+ setComponentReady(true);
170
+ } else {
171
+ onError("Failed to retrieve public key.");
172
+ }
173
+ case 5:
174
+ case "end":
175
+ return _context2.stop();
176
+ }
177
+ }, _callee2);
178
+ }));
179
+ return function manageClient() {
180
+ return _ref3.apply(this, arguments);
181
+ };
182
+ }();
183
+ manageClient();
184
+ }, [indexedDbClient, turnkey]);
203
185
  if (!componentReady) {
204
186
  return jsx("div", {
205
187
  className: styles.defaultLoader,
@@ -285,31 +267,34 @@ var Auth = function Auth(_ref) {
285
267
  case 21:
286
268
  case 22:
287
269
  _context3.next = 24;
288
- return indexedDbClient.getPublicKey();
270
+ return indexedDbClient.resetKeyPair();
289
271
  case 24:
272
+ _context3.next = 26;
273
+ return indexedDbClient.getPublicKey();
274
+ case 26:
290
275
  pubKey = _context3.sent;
291
- _context3.next = 27;
276
+ _context3.next = 29;
292
277
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.loginWithPasskey({
293
278
  sessionType: SessionType.READ_WRITE,
294
279
  publicKey: pubKey,
295
280
  expirationSeconds: (_authConfig$sessionLe = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe === void 0 ? void 0 : _authConfig$sessionLe.toString()
296
281
  });
297
- case 27:
298
- _context3.next = 29;
299
- return onAuthSuccess();
300
282
  case 29:
301
- _context3.next = 35;
302
- break;
283
+ _context3.next = 31;
284
+ return onAuthSuccess();
303
285
  case 31:
304
- _context3.prev = 31;
286
+ _context3.next = 37;
287
+ break;
288
+ case 33:
289
+ _context3.prev = 33;
305
290
  _context3.t1 = _context3["catch"](4);
306
291
  setPasskeySignupError(authErrors.passkey.timeoutOrNotAllowed);
307
292
  console.error("Error during passkey signup: ", _context3.t1);
308
- case 35:
293
+ case 37:
309
294
  case "end":
310
295
  return _context3.stop();
311
296
  }
312
- }, _callee3, null, [[4, 31]]);
297
+ }, _callee3, null, [[4, 33]]);
313
298
  }));
314
299
  return function handleSignupWithPasskey() {
315
300
  return _ref4.apply(this, arguments);
@@ -324,35 +309,38 @@ var Auth = function Auth(_ref) {
324
309
  _context4.prev = 0;
325
310
  setLoading("passkey");
326
311
  _context4.next = 4;
327
- return indexedDbClient.getPublicKey();
312
+ return indexedDbClient === null || indexedDbClient === void 0 ? void 0 : indexedDbClient.resetKeyPair();
328
313
  case 4:
314
+ _context4.next = 6;
315
+ return indexedDbClient.getPublicKey();
316
+ case 6:
329
317
  pubKey = _context4.sent;
330
- _context4.next = 7;
318
+ _context4.next = 9;
331
319
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.loginWithPasskey({
332
320
  sessionType: SessionType.READ_WRITE,
333
321
  publicKey: pubKey,
334
322
  expirationSeconds: (_authConfig$sessionLe2 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe2 === void 0 ? void 0 : _authConfig$sessionLe2.toString()
335
323
  });
336
- case 7:
337
- _context4.next = 9;
338
- return onAuthSuccess();
339
324
  case 9:
340
- _context4.next = 15;
341
- break;
325
+ _context4.next = 11;
326
+ return onAuthSuccess();
342
327
  case 11:
343
- _context4.prev = 11;
328
+ _context4.next = 17;
329
+ break;
330
+ case 13:
331
+ _context4.prev = 13;
344
332
  _context4.t0 = _context4["catch"](0);
345
333
  onError(authErrors.passkey.loginFailed);
346
334
  console.error("Error during passkey login: ", _context4.t0);
347
- case 15:
348
- _context4.prev = 15;
335
+ case 17:
336
+ _context4.prev = 17;
349
337
  setLoading(undefined);
350
- return _context4.finish(15);
351
- case 18:
338
+ return _context4.finish(17);
339
+ case 20:
352
340
  case "end":
353
341
  return _context4.stop();
354
342
  }
355
- }, _callee4, null, [[0, 11, 15, 18]]);
343
+ }, _callee4, null, [[0, 13, 17, 20]]);
356
344
  }));
357
345
  return function handleLoginWithPasskey() {
358
346
  return _ref6.apply(this, arguments);
@@ -415,10 +403,20 @@ var Auth = function Auth(_ref) {
415
403
  }();
416
404
  var handleOAuthLogin = /*#__PURE__*/function () {
417
405
  var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(credential, providerName) {
418
- var createSuborgData, resp, suborgIds, suborgId, sessionResponse;
406
+ var pubKey, createSuborgData, resp, suborgIds, suborgId, sessionResponse;
419
407
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
420
408
  while (1) switch (_context6.prev = _context6.next) {
421
409
  case 0:
410
+ _context6.next = 2;
411
+ return indexedDbClient === null || indexedDbClient === void 0 ? void 0 : indexedDbClient.getPublicKey();
412
+ case 2:
413
+ pubKey = _context6.sent;
414
+ if (pubKey) {
415
+ _context6.next = 5;
416
+ break;
417
+ }
418
+ return _context6.abrupt("return");
419
+ case 5:
422
420
  setOauthLoading(providerName);
423
421
  createSuborgData = {
424
422
  oauthProviders: [{
@@ -429,47 +427,47 @@ var Auth = function Auth(_ref) {
429
427
  if (customAccounts) {
430
428
  createSuborgData.customAccounts = customAccounts;
431
429
  }
432
- _context6.next = 5;
430
+ _context6.next = 10;
433
431
  return server.getOrCreateSuborg({
434
432
  filterType: FilterType.OidcToken,
435
433
  filterValue: credential,
436
434
  additionalData: createSuborgData
437
435
  });
438
- case 5:
436
+ case 10:
439
437
  resp = _context6.sent;
440
438
  suborgIds = resp === null || resp === void 0 ? void 0 : resp.subOrganizationIds;
441
439
  if (!(!suborgIds || suborgIds.length === 0)) {
442
- _context6.next = 10;
440
+ _context6.next = 15;
443
441
  break;
444
442
  }
445
443
  onError(authErrors.oauth.loginFailed);
446
444
  return _context6.abrupt("return");
447
- case 10:
445
+ case 15:
448
446
  suborgId = suborgIds[0];
449
- _context6.next = 13;
447
+ _context6.next = 18;
450
448
  return server.oauthLogin({
451
449
  suborgID: suborgId,
452
450
  oidcToken: credential,
453
- publicKey: publicKey,
451
+ publicKey: pubKey,
454
452
  sessionLengthSeconds: authConfig.sessionLengthSeconds
455
453
  });
456
- case 13:
454
+ case 18:
457
455
  sessionResponse = _context6.sent;
458
456
  if (!(sessionResponse && sessionResponse.session)) {
459
- _context6.next = 21;
457
+ _context6.next = 26;
460
458
  break;
461
459
  }
462
- _context6.next = 17;
460
+ _context6.next = 22;
463
461
  return indexedDbClient.loginWithSession(sessionResponse.session);
464
- case 17:
465
- _context6.next = 19;
462
+ case 22:
463
+ _context6.next = 24;
466
464
  return onAuthSuccess();
467
- case 19:
468
- _context6.next = 22;
465
+ case 24:
466
+ _context6.next = 27;
469
467
  break;
470
- case 21:
468
+ case 26:
471
469
  onError(authErrors.oauth.loginFailed);
472
- case 22:
470
+ case 27:
473
471
  case "end":
474
472
  return _context6.stop();
475
473
  }
@@ -481,7 +479,7 @@ var Auth = function Auth(_ref) {
481
479
  }();
482
480
  var handleLoginWithWallet = /*#__PURE__*/function () {
483
481
  var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
484
- var _authConfig$sessionLe3, _publicKey3, _walletClient$getWall, type, resp, suborgIds, pubKey;
482
+ var _authConfig$sessionLe3, publicKey, _walletClient$getWall, type, resp, suborgIds, pubKey;
485
483
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
486
484
  while (1) switch (_context7.prev = _context7.next) {
487
485
  case 0:
@@ -496,8 +494,8 @@ var Auth = function Auth(_ref) {
496
494
  _context7.next = 6;
497
495
  return walletClient.getPublicKey();
498
496
  case 6:
499
- _publicKey3 = _context7.sent;
500
- if (_publicKey3) {
497
+ publicKey = _context7.sent;
498
+ if (publicKey) {
501
499
  _context7.next = 9;
502
500
  break;
503
501
  }
@@ -507,10 +505,10 @@ var Auth = function Auth(_ref) {
507
505
  _context7.next = 12;
508
506
  return server.getOrCreateSuborg({
509
507
  filterType: FilterType.PublicKey,
510
- filterValue: _publicKey3,
508
+ filterValue: publicKey,
511
509
  additionalData: {
512
510
  wallet: {
513
- publicKey: _publicKey3,
511
+ publicKey: publicKey,
514
512
  type: type
515
513
  }
516
514
  }
@@ -526,35 +524,38 @@ var Auth = function Auth(_ref) {
526
524
  return _context7.abrupt("return");
527
525
  case 17:
528
526
  _context7.next = 19;
529
- return indexedDbClient.getPublicKey();
527
+ return indexedDbClient.resetKeyPair();
530
528
  case 19:
529
+ _context7.next = 21;
530
+ return indexedDbClient.getPublicKey();
531
+ case 21:
531
532
  pubKey = _context7.sent;
532
- _context7.next = 22;
533
+ _context7.next = 24;
533
534
  return walletClient.loginWithWallet({
534
535
  sessionType: SessionType.READ_WRITE,
535
536
  publicKey: pubKey,
536
537
  expirationSeconds: (_authConfig$sessionLe3 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe3 === void 0 ? void 0 : _authConfig$sessionLe3.toString()
537
538
  });
538
- case 22:
539
- _context7.next = 24;
540
- return onAuthSuccess();
541
539
  case 24:
542
- _context7.next = 30;
543
- break;
540
+ _context7.next = 26;
541
+ return onAuthSuccess();
544
542
  case 26:
545
- _context7.prev = 26;
543
+ _context7.next = 32;
544
+ break;
545
+ case 28:
546
+ _context7.prev = 28;
546
547
  _context7.t0 = _context7["catch"](1);
547
548
  onError(_context7.t0.message || authErrors.wallet.loginFailed);
548
549
  console.error("Error during wallet login: ", _context7.t0);
549
- case 30:
550
- _context7.prev = 30;
550
+ case 32:
551
+ _context7.prev = 32;
551
552
  setLoading(undefined);
552
- return _context7.finish(30);
553
- case 33:
553
+ return _context7.finish(32);
554
+ case 35:
554
555
  case "end":
555
556
  return _context7.stop();
556
557
  }
557
- }, _callee7, null, [[1, 26, 30, 33]]);
558
+ }, _callee7, null, [[1, 28, 32, 35]]);
558
559
  }));
559
560
  return function handleLoginWithWallet() {
560
561
  return _ref9.apply(this, arguments);
@@ -594,14 +595,12 @@ var Auth = function Auth(_ref) {
594
595
  layout: layout,
595
596
  clientId: (_authConfig$googleCli = authConfig.googleClientId) !== null && _authConfig$googleCli !== void 0 ? _authConfig$googleCli : process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID,
596
597
  openInPage: authConfig.openOAuthInPage,
597
- publicKey: publicKey,
598
598
  onSuccess: function onSuccess(response) {
599
599
  return handleOAuthLogin(response.idToken, "Google");
600
600
  }
601
601
  }), appleEnabled && jsx(AppleAuthButton, {
602
602
  layout: layout,
603
603
  clientId: (_authConfig$appleClie = authConfig.appleClientId) !== null && _authConfig$appleClie !== void 0 ? _authConfig$appleClie : process.env.NEXT_PUBLIC_APPLE_CLIENT_ID,
604
- publicKey: publicKey,
605
604
  openInPage: authConfig.openOAuthInPage,
606
605
  onSuccess: function onSuccess(response) {
607
606
  return handleOAuthLogin(response.idToken, "Apple");
@@ -609,7 +608,6 @@ var Auth = function Auth(_ref) {
609
608
  }), facebookEnabled && jsx(FacebookAuthButton, {
610
609
  layout: layout,
611
610
  clientId: (_authConfig$facebookC = authConfig.facebookClientId) !== null && _authConfig$facebookC !== void 0 ? _authConfig$facebookC : process.env.NEXT_PUBLIC_FACEBOOK_CLIENT_ID,
612
- publicKey: publicKey,
613
611
  openInPage: authConfig.openOAuthInPage,
614
612
  onSuccess: function onSuccess(response) {
615
613
  return handleOAuthLogin(response.id_token, "Facebook");