@turnkey/sdk-react 4.2.0 → 4.2.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.
@@ -156,6 +156,24 @@ var Auth = function Auth(_ref) {
156
156
  useEffect(function () {
157
157
  if (authIframeClient) {
158
158
  setComponentReady(true);
159
+ var updateIframeKey = /*#__PURE__*/function () {
160
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
161
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
162
+ while (1) switch (_context2.prev = _context2.next) {
163
+ case 0:
164
+ _context2.next = 2;
165
+ return authIframeClient.initEmbeddedKey();
166
+ case 2:
167
+ case "end":
168
+ return _context2.stop();
169
+ }
170
+ }, _callee2);
171
+ }));
172
+ return function updateIframeKey() {
173
+ return _ref3.apply(this, arguments);
174
+ };
175
+ }();
176
+ updateIframeKey();
159
177
  }
160
178
  }, [authIframeClient]);
161
179
  if (!componentReady) {
@@ -177,10 +195,10 @@ var Auth = function Auth(_ref) {
177
195
  return (_phoneNumber$isValid = phoneNumber === null || phoneNumber === void 0 ? void 0 : phoneNumber.isValid()) !== null && _phoneNumber$isValid !== void 0 ? _phoneNumber$isValid : false;
178
196
  };
179
197
  var handleSignupWithPasskey = /*#__PURE__*/function () {
180
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
181
- var siteInfo, _authConfig$sessionLe, _passkeyConfig$name, _passkeyConfig$displa, _ref4, encodedChallenge, attestation, response;
182
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
183
- while (1) switch (_context2.prev = _context2.next) {
198
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
199
+ var siteInfo, _authConfig$sessionLe, _passkeyConfig$name, _passkeyConfig$displa, _ref5, encodedChallenge, attestation, response, iframePublicKey;
200
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
201
+ while (1) switch (_context3.prev = _context3.next) {
184
202
  case 0:
185
203
  setPasskeySignupError("");
186
204
  siteInfo = "".concat(new URL(window.location.href).hostname, " - ").concat(new Date().toLocaleString(undefined, {
@@ -193,12 +211,12 @@ var Auth = function Auth(_ref) {
193
211
  }));
194
212
  setPasskeySignupScreen(false);
195
213
  setPasskeyCreationScreen(true);
196
- _context2.prev = 4;
214
+ _context3.prev = 4;
197
215
  if (passkeyCreated) {
198
- _context2.next = 22;
216
+ _context3.next = 22;
199
217
  break;
200
218
  }
201
- _context2.next = 8;
219
+ _context3.next = 8;
202
220
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.createUserPasskey({
203
221
  publicKey: {
204
222
  user: {
@@ -208,21 +226,21 @@ var Auth = function Auth(_ref) {
208
226
  }
209
227
  });
210
228
  case 8:
211
- _context2.t0 = _context2.sent;
212
- if (_context2.t0) {
213
- _context2.next = 11;
229
+ _context3.t0 = _context3.sent;
230
+ if (_context3.t0) {
231
+ _context3.next = 11;
214
232
  break;
215
233
  }
216
- _context2.t0 = {};
234
+ _context3.t0 = {};
217
235
  case 11:
218
- _ref4 = _context2.t0;
219
- encodedChallenge = _ref4.encodedChallenge;
220
- attestation = _ref4.attestation;
236
+ _ref5 = _context3.t0;
237
+ encodedChallenge = _ref5.encodedChallenge;
238
+ attestation = _ref5.attestation;
221
239
  if (!(encodedChallenge && attestation)) {
222
- _context2.next = 21;
240
+ _context3.next = 21;
223
241
  break;
224
242
  }
225
- _context2.next = 17;
243
+ _context3.next = 17;
226
244
  return server.createSuborg(_objectSpread2({
227
245
  email: email,
228
246
  passkey: {
@@ -234,113 +252,129 @@ var Auth = function Auth(_ref) {
234
252
  customAccounts: customAccounts
235
253
  }));
236
254
  case 17:
237
- response = _context2.sent;
255
+ response = _context3.sent;
238
256
  if (response !== null && response !== void 0 && response.subOrganizationId) {
239
257
  setPasskeyCreated(true);
240
258
  }
241
- _context2.next = 22;
259
+ _context3.next = 22;
242
260
  break;
243
261
  case 21:
244
262
  case 22:
245
- _context2.next = 24;
263
+ _context3.next = 24;
264
+ return authIframeClient.initEmbeddedKey();
265
+ case 24:
266
+ iframePublicKey = _context3.sent;
267
+ _context3.next = 27;
246
268
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.loginWithPasskey({
247
269
  sessionType: SessionType.READ_WRITE,
248
270
  iframeClient: authIframeClient,
249
- targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey,
271
+ targetPublicKey: iframePublicKey,
250
272
  expirationSeconds: (_authConfig$sessionLe = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe === void 0 ? void 0 : _authConfig$sessionLe.toString()
251
273
  });
252
- case 24:
253
- _context2.next = 26;
274
+ case 27:
275
+ _context3.next = 29;
254
276
  return onAuthSuccess();
255
- case 26:
256
- _context2.next = 32;
277
+ case 29:
278
+ _context3.next = 35;
257
279
  break;
258
- case 28:
259
- _context2.prev = 28;
260
- _context2.t1 = _context2["catch"](4);
280
+ case 31:
281
+ _context3.prev = 31;
282
+ _context3.t1 = _context3["catch"](4);
261
283
  setPasskeySignupError(authErrors.passkey.timeoutOrNotAllowed);
262
- console.error("Error during passkey signup: ", _context2.t1);
263
- case 32:
284
+ console.error("Error during passkey signup: ", _context3.t1);
285
+ case 35:
264
286
  case "end":
265
- return _context2.stop();
287
+ return _context3.stop();
266
288
  }
267
- }, _callee2, null, [[4, 28]]);
289
+ }, _callee3, null, [[4, 31]]);
268
290
  }));
269
291
  return function handleSignupWithPasskey() {
270
- return _ref3.apply(this, arguments);
292
+ return _ref4.apply(this, arguments);
271
293
  };
272
294
  }();
273
295
  var handleLoginWithPasskey = /*#__PURE__*/function () {
274
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
275
- var _authConfig$sessionLe2;
276
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
277
- while (1) switch (_context3.prev = _context3.next) {
296
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
297
+ var _authConfig$sessionLe2, iframePublicKey;
298
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
299
+ while (1) switch (_context4.prev = _context4.next) {
278
300
  case 0:
279
- _context3.prev = 0;
301
+ _context4.prev = 0;
280
302
  setLoading("passkey");
281
- _context3.next = 4;
303
+ _context4.next = 4;
304
+ return authIframeClient.initEmbeddedKey();
305
+ case 4:
306
+ iframePublicKey = _context4.sent;
307
+ _context4.next = 7;
282
308
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.loginWithPasskey({
283
309
  sessionType: SessionType.READ_WRITE,
284
310
  iframeClient: authIframeClient,
285
- targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey,
311
+ targetPublicKey: iframePublicKey,
286
312
  expirationSeconds: (_authConfig$sessionLe2 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe2 === void 0 ? void 0 : _authConfig$sessionLe2.toString()
287
313
  });
288
- case 4:
289
- _context3.next = 6;
314
+ case 7:
315
+ _context4.next = 9;
290
316
  return onAuthSuccess();
291
- case 6:
292
- _context3.next = 12;
317
+ case 9:
318
+ _context4.next = 15;
293
319
  break;
294
- case 8:
295
- _context3.prev = 8;
296
- _context3.t0 = _context3["catch"](0);
320
+ case 11:
321
+ _context4.prev = 11;
322
+ _context4.t0 = _context4["catch"](0);
297
323
  onError(authErrors.passkey.loginFailed);
298
- console.error("Error during passkey login: ", _context3.t0);
299
- case 12:
300
- _context3.prev = 12;
301
- setLoading(undefined);
302
- return _context3.finish(12);
324
+ console.error("Error during passkey login: ", _context4.t0);
303
325
  case 15:
326
+ _context4.prev = 15;
327
+ setLoading(undefined);
328
+ return _context4.finish(15);
329
+ case 18:
304
330
  case "end":
305
- return _context3.stop();
331
+ return _context4.stop();
306
332
  }
307
- }, _callee3, null, [[0, 8, 12, 15]]);
333
+ }, _callee4, null, [[0, 11, 15, 18]]);
308
334
  }));
309
335
  return function handleLoginWithPasskey() {
310
- return _ref5.apply(this, arguments);
336
+ return _ref6.apply(this, arguments);
311
337
  };
312
338
  }();
313
339
  var handleOtpLogin = /*#__PURE__*/function () {
314
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(type, value, otpType) {
340
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(type, value, otpType) {
315
341
  var _otpConfig$otpLength, _otpConfig$alphanumer;
316
- var createSuborgData, resp, suborgIds, suborgId, initAuthResponse;
317
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
318
- while (1) switch (_context4.prev = _context4.next) {
342
+ var createSuborgData, resp, suborgIds, suborgId, iframePublicKey, initAuthResponse;
343
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
344
+ while (1) switch (_context5.prev = _context5.next) {
319
345
  case 0:
320
346
  setLoading(otpType);
321
347
  createSuborgData = {};
322
- if (type === FilterType.Email) createSuborgData.email = value;else if (type === FilterType.PhoneNumber) createSuborgData.phoneNumber = value;
348
+ if (type === FilterType.Email) {
349
+ createSuborgData.email = value;
350
+ } else if (type === FilterType.PhoneNumber) {
351
+ createSuborgData.phoneNumber = value;
352
+ }
323
353
  if (customAccounts) {
324
354
  createSuborgData.customAccounts = customAccounts;
325
355
  }
326
- _context4.next = 6;
356
+ _context5.next = 6;
327
357
  return server.getOrCreateSuborg({
328
358
  filterType: type,
329
359
  filterValue: value,
330
360
  additionalData: createSuborgData
331
361
  });
332
362
  case 6:
333
- resp = _context4.sent;
363
+ resp = _context5.sent;
334
364
  suborgIds = resp === null || resp === void 0 ? void 0 : resp.subOrganizationIds;
335
365
  if (!(!suborgIds || suborgIds.length === 0)) {
336
- _context4.next = 11;
366
+ _context5.next = 11;
337
367
  break;
338
368
  }
339
369
  onError(authErrors.otp.sendFailed);
340
- return _context4.abrupt("return");
370
+ return _context5.abrupt("return");
341
371
  case 11:
342
372
  suborgId = suborgIds[0];
343
- _context4.next = 14;
373
+ _context5.next = 14;
374
+ return authIframeClient.initEmbeddedKey();
375
+ case 14:
376
+ iframePublicKey = _context5.sent;
377
+ _context5.next = 17;
344
378
  return server.sendOtp(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
345
379
  suborgID: suborgId,
346
380
  otpType: otpType,
@@ -354,10 +388,10 @@ var Auth = function Auth(_ref) {
354
388
  }), {}, {
355
389
  otpLength: (_otpConfig$otpLength = otpConfig === null || otpConfig === void 0 ? void 0 : otpConfig.otpLength) !== null && _otpConfig$otpLength !== void 0 ? _otpConfig$otpLength : 6,
356
390
  alphanumeric: (_otpConfig$alphanumer = otpConfig === null || otpConfig === void 0 ? void 0 : otpConfig.alphanumeric) !== null && _otpConfig$alphanumer !== void 0 ? _otpConfig$alphanumer : false,
357
- userIdentifier: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey
391
+ userIdentifier: iframePublicKey
358
392
  }));
359
- case 14:
360
- initAuthResponse = _context4.sent;
393
+ case 17:
394
+ initAuthResponse = _context5.sent;
361
395
  if (initAuthResponse && initAuthResponse.otpId) {
362
396
  setSuborgId(suborgId);
363
397
  setOtpId(initAuthResponse === null || initAuthResponse === void 0 ? void 0 : initAuthResponse.otpId);
@@ -366,21 +400,21 @@ var Auth = function Auth(_ref) {
366
400
  onError(authErrors.otp.sendFailed);
367
401
  }
368
402
  setLoading(undefined);
369
- case 17:
403
+ case 20:
370
404
  case "end":
371
- return _context4.stop();
405
+ return _context5.stop();
372
406
  }
373
- }, _callee4);
407
+ }, _callee5);
374
408
  }));
375
409
  return function handleOtpLogin(_x, _x2, _x3) {
376
- return _ref6.apply(this, arguments);
410
+ return _ref7.apply(this, arguments);
377
411
  };
378
412
  }();
379
413
  var handleOAuthLogin = /*#__PURE__*/function () {
380
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(credential, providerName) {
381
- var createSuborgData, resp, suborgIds, suborgId, oauthSession;
382
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
383
- while (1) switch (_context5.prev = _context5.next) {
414
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(credential, providerName) {
415
+ var createSuborgData, resp, suborgIds, suborgId, iframePublicKey, oauthSession;
416
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
417
+ while (1) switch (_context6.prev = _context6.next) {
384
418
  case 0:
385
419
  setOauthLoading(providerName);
386
420
  createSuborgData = {
@@ -392,82 +426,86 @@ var Auth = function Auth(_ref) {
392
426
  if (customAccounts) {
393
427
  createSuborgData.customAccounts = customAccounts;
394
428
  }
395
- _context5.next = 5;
429
+ _context6.next = 5;
396
430
  return server.getOrCreateSuborg({
397
431
  filterType: FilterType.OidcToken,
398
432
  filterValue: credential,
399
433
  additionalData: createSuborgData
400
434
  });
401
435
  case 5:
402
- resp = _context5.sent;
436
+ resp = _context6.sent;
403
437
  suborgIds = resp === null || resp === void 0 ? void 0 : resp.subOrganizationIds;
404
438
  if (!(!suborgIds || suborgIds.length === 0)) {
405
- _context5.next = 10;
439
+ _context6.next = 10;
406
440
  break;
407
441
  }
408
442
  onError(authErrors.oauth.loginFailed);
409
- return _context5.abrupt("return");
443
+ return _context6.abrupt("return");
410
444
  case 10:
411
445
  suborgId = suborgIds[0];
412
- _context5.next = 13;
446
+ _context6.next = 13;
447
+ return authIframeClient.initEmbeddedKey();
448
+ case 13:
449
+ iframePublicKey = _context6.sent;
450
+ _context6.next = 16;
413
451
  return server.oauth({
414
452
  suborgID: suborgId,
415
453
  oidcToken: credential,
416
- targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey,
454
+ targetPublicKey: iframePublicKey,
417
455
  sessionLengthSeconds: authConfig.sessionLengthSeconds
418
456
  });
419
- case 13:
420
- oauthSession = _context5.sent;
457
+ case 16:
458
+ oauthSession = _context6.sent;
421
459
  if (!(oauthSession && oauthSession.token)) {
422
- _context5.next = 21;
460
+ _context6.next = 24;
423
461
  break;
424
462
  }
425
- _context5.next = 17;
463
+ _context6.next = 20;
426
464
  return authIframeClient.loginWithSession(oauthSession);
427
- case 17:
428
- _context5.next = 19;
465
+ case 20:
466
+ _context6.next = 22;
429
467
  return onAuthSuccess();
430
- case 19:
431
- _context5.next = 22;
468
+ case 22:
469
+ _context6.next = 25;
432
470
  break;
433
- case 21:
471
+ case 24:
434
472
  onError(authErrors.oauth.loginFailed);
435
- case 22:
473
+ case 25:
436
474
  case "end":
437
- return _context5.stop();
475
+ return _context6.stop();
438
476
  }
439
- }, _callee5);
477
+ }, _callee6);
440
478
  }));
441
479
  return function handleOAuthLogin(_x4, _x5) {
442
- return _ref7.apply(this, arguments);
480
+ return _ref8.apply(this, arguments);
443
481
  };
444
482
  }();
445
483
  var handleLoginWithWallet = /*#__PURE__*/function () {
446
- var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
447
- var _authConfig$sessionLe3, publicKey, _walletClient$getWall, type, resp, suborgIds;
448
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
449
- while (1) switch (_context6.prev = _context6.next) {
484
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
485
+ var _authConfig$sessionLe3, publicKey, _walletClient$getWall, type, resp, suborgIds, iframePublicKey;
486
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
487
+ while (1) switch (_context7.prev = _context7.next) {
450
488
  case 0:
451
489
  setLoading("wallet");
452
- _context6.prev = 1;
490
+ _context7.prev = 1;
453
491
  if (walletClient) {
454
- _context6.next = 4;
492
+ _context7.next = 4;
455
493
  break;
456
494
  }
457
495
  throw new Error("Wallet client not initialized");
458
496
  case 4:
459
- _context6.next = 6;
497
+ _context7.next = 6;
460
498
  return walletClient.getPublicKey();
461
499
  case 6:
462
- publicKey = _context6.sent;
500
+ publicKey = _context7.sent;
463
501
  if (publicKey) {
464
- _context6.next = 9;
502
+ _context7.next = 9;
465
503
  break;
466
504
  }
467
505
  throw new Error(authErrors.wallet.noPublicKey);
468
506
  case 9:
469
507
  _walletClient$getWall = walletClient.getWalletInterface(), type = _walletClient$getWall.type;
470
- _context6.next = 12;
508
+ _context7.next = 12;
471
509
  return server.getOrCreateSuborg({
472
510
  filterType: FilterType.PublicKey,
473
511
  filterValue: publicKey,
@@ -479,45 +517,49 @@ var Auth = function Auth(_ref) {
479
517
  }
480
518
  });
481
519
  case 12:
482
- resp = _context6.sent;
520
+ resp = _context7.sent;
483
521
  suborgIds = resp === null || resp === void 0 ? void 0 : resp.subOrganizationIds;
484
522
  if (!(!suborgIds || suborgIds.length === 0)) {
485
- _context6.next = 17;
523
+ _context7.next = 17;
486
524
  break;
487
525
  }
488
526
  onError(authErrors.wallet.loginFailed);
489
- return _context6.abrupt("return");
527
+ return _context7.abrupt("return");
490
528
  case 17:
491
- _context6.next = 19;
529
+ _context7.next = 19;
530
+ return authIframeClient.initEmbeddedKey();
531
+ case 19:
532
+ iframePublicKey = _context7.sent;
533
+ _context7.next = 22;
492
534
  return walletClient.loginWithWallet({
493
535
  sessionType: SessionType.READ_WRITE,
494
536
  iframeClient: authIframeClient,
495
- targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey,
537
+ targetPublicKey: iframePublicKey,
496
538
  expirationSeconds: (_authConfig$sessionLe3 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe3 === void 0 ? void 0 : _authConfig$sessionLe3.toString()
497
539
  });
498
- case 19:
499
- _context6.next = 21;
540
+ case 22:
541
+ _context7.next = 24;
500
542
  return onAuthSuccess();
501
- case 21:
502
- _context6.next = 27;
543
+ case 24:
544
+ _context7.next = 30;
503
545
  break;
504
- case 23:
505
- _context6.prev = 23;
506
- _context6.t0 = _context6["catch"](1);
507
- onError(_context6.t0.message || authErrors.wallet.loginFailed);
508
- console.error("Error during wallet login: ", _context6.t0);
509
- case 27:
510
- _context6.prev = 27;
511
- setLoading(undefined);
512
- return _context6.finish(27);
546
+ case 26:
547
+ _context7.prev = 26;
548
+ _context7.t0 = _context7["catch"](1);
549
+ onError(_context7.t0.message || authErrors.wallet.loginFailed);
550
+ console.error("Error during wallet login: ", _context7.t0);
513
551
  case 30:
552
+ _context7.prev = 30;
553
+ setLoading(undefined);
554
+ return _context7.finish(30);
555
+ case 33:
514
556
  case "end":
515
- return _context6.stop();
557
+ return _context7.stop();
516
558
  }
517
- }, _callee6, null, [[1, 23, 27, 30]]);
559
+ }, _callee7, null, [[1, 26, 30, 33]]);
518
560
  }));
519
561
  return function handleLoginWithWallet() {
520
- return _ref8.apply(this, arguments);
562
+ return _ref9.apply(this, arguments);
521
563
  };
522
564
  }();
523
565
  var renderBackButton = function renderBackButton() {