@turnkey/sdk-react 5.4.0 → 5.4.1

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 (44) hide show
  1. package/CHANGELOG.md +11 -10
  2. package/dist/_virtual/_rollupPluginBabelHelpers.mjs +95 -256
  3. package/dist/_virtual/_rollupPluginBabelHelpers.mjs.map +1 -1
  4. package/dist/components/auth/Apple.js.map +1 -1
  5. package/dist/components/auth/Apple.mjs +27 -29
  6. package/dist/components/auth/Apple.mjs.map +1 -1
  7. package/dist/components/auth/Auth.js.map +1 -1
  8. package/dist/components/auth/Auth.mjs +277 -272
  9. package/dist/components/auth/Auth.mjs.map +1 -1
  10. package/dist/components/auth/Facebook.js.map +1 -1
  11. package/dist/components/auth/Facebook.mjs +55 -58
  12. package/dist/components/auth/Facebook.mjs.map +1 -1
  13. package/dist/components/auth/Google.js.map +1 -1
  14. package/dist/components/auth/Google.mjs +27 -29
  15. package/dist/components/auth/Google.mjs.map +1 -1
  16. package/dist/components/auth/OtpVerification.js.map +1 -1
  17. package/dist/components/auth/OtpVerification.mjs +61 -62
  18. package/dist/components/auth/OtpVerification.mjs.map +1 -1
  19. package/dist/components/auth/PhoneInput.js.map +1 -1
  20. package/dist/components/auth/PhoneInput.mjs.map +1 -1
  21. package/dist/components/auth/TurnkeyThemeProvider.js.map +1 -1
  22. package/dist/components/auth/TurnkeyThemeProvider.mjs.map +1 -1
  23. package/dist/components/auth/constants.js.map +1 -1
  24. package/dist/components/auth/constants.mjs.map +1 -1
  25. package/dist/components/auth/facebookUtils.js.map +1 -1
  26. package/dist/components/auth/facebookUtils.mjs +17 -23
  27. package/dist/components/auth/facebookUtils.mjs.map +1 -1
  28. package/dist/components/auth/otp.js.map +1 -1
  29. package/dist/components/auth/otp.mjs.map +1 -1
  30. package/dist/components/auth/utils.js.map +1 -1
  31. package/dist/components/export/Export.js.map +1 -1
  32. package/dist/components/export/Export.mjs +56 -60
  33. package/dist/components/export/Export.mjs.map +1 -1
  34. package/dist/components/import/Import.js.map +1 -1
  35. package/dist/components/import/Import.mjs +64 -67
  36. package/dist/components/import/Import.mjs.map +1 -1
  37. package/dist/contexts/TurnkeyContext.js.map +1 -1
  38. package/dist/contexts/TurnkeyContext.mjs +15 -16
  39. package/dist/contexts/TurnkeyContext.mjs.map +1 -1
  40. package/dist/hooks/use-session.js.map +1 -1
  41. package/dist/hooks/use-session.mjs.map +1 -1
  42. package/dist/hooks/use-turnkey.js.map +1 -1
  43. package/dist/hooks/use-turnkey.mjs.map +1 -1
  44. package/package.json +6 -6
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { slicedToArray as _slicedToArray, objectSpread2 as _objectSpread2, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from '../../_virtual/_rollupPluginBabelHelpers.mjs';
2
+ import { slicedToArray as _slicedToArray, objectSpread2 as _objectSpread2, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator } from '../../_virtual/_rollupPluginBabelHelpers.mjs';
3
3
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
4
4
  import styles from './Auth.module.css.mjs';
5
5
  import React, { useState, useEffect } from 'react';
@@ -117,29 +117,28 @@ var Auth = function Auth(_ref) {
117
117
  passkeyCreated = _useState20[0],
118
118
  setPasskeyCreated = _useState20[1];
119
119
  var handleResendCode = /*#__PURE__*/function () {
120
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
121
- return _regeneratorRuntime().wrap(function _callee$(_context) {
122
- while (1) switch (_context.prev = _context.next) {
120
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
121
+ return _regenerator().w(function (_context) {
122
+ while (1) switch (_context.n) {
123
123
  case 0:
124
124
  if (!(step === OtpType.Email)) {
125
- _context.next = 5;
125
+ _context.n = 2;
126
126
  break;
127
127
  }
128
- _context.next = 3;
128
+ _context.n = 1;
129
129
  return handleSendOtp(email, OtpType.Email);
130
- case 3:
131
- _context.next = 8;
130
+ case 1:
131
+ _context.n = 3;
132
132
  break;
133
- case 5:
133
+ case 2:
134
134
  if (!(step === OtpType.Sms)) {
135
- _context.next = 8;
135
+ _context.n = 3;
136
136
  break;
137
137
  }
138
- _context.next = 8;
138
+ _context.n = 3;
139
139
  return handleSendOtp(phone, OtpType.Sms);
140
- case 8:
141
- case "end":
142
- return _context.stop();
140
+ case 3:
141
+ return _context.a(2);
143
142
  }
144
143
  }, _callee);
145
144
  }));
@@ -149,27 +148,26 @@ var Auth = function Auth(_ref) {
149
148
  }();
150
149
  useEffect(function () {
151
150
  var manageClient = /*#__PURE__*/function () {
152
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
151
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
153
152
  var retrievedPublicKey;
154
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
155
- while (1) switch (_context2.prev = _context2.next) {
153
+ return _regenerator().w(function (_context2) {
154
+ while (1) switch (_context2.n) {
156
155
  case 0:
157
156
  if (!(indexedDbClient && turnkey)) {
158
- _context2.next = 5;
157
+ _context2.n = 2;
159
158
  break;
160
159
  }
161
- _context2.next = 3;
160
+ _context2.n = 1;
162
161
  return indexedDbClient.getPublicKey();
163
- case 3:
164
- retrievedPublicKey = _context2.sent;
162
+ case 1:
163
+ retrievedPublicKey = _context2.v;
165
164
  if (retrievedPublicKey) {
166
165
  setComponentReady(true);
167
166
  } else {
168
167
  onError("Failed to retrieve public key.");
169
168
  }
170
- case 5:
171
- case "end":
172
- return _context2.stop();
169
+ case 2:
170
+ return _context2.a(2);
173
171
  }
174
172
  }, _callee2);
175
173
  }));
@@ -198,10 +196,10 @@ var Auth = function Auth(_ref) {
198
196
  return (_phoneNumber$isValid = phoneNumber === null || phoneNumber === void 0 ? void 0 : phoneNumber.isValid()) !== null && _phoneNumber$isValid !== void 0 ? _phoneNumber$isValid : false;
199
197
  };
200
198
  var handleSignupWithPasskey = /*#__PURE__*/function () {
201
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
202
- var siteInfo, _authConfig$sessionLe, _passkeyConfig$name, _passkeyConfig$displa, _ref5, encodedChallenge, attestation, response, pubKey;
203
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
204
- while (1) switch (_context3.prev = _context3.next) {
199
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
200
+ var siteInfo, _authConfig$sessionLe, _passkeyConfig$name, _passkeyConfig$displa, _ref5, encodedChallenge, attestation, response, pubKey, _t, _t2;
201
+ return _regenerator().w(function (_context3) {
202
+ while (1) switch (_context3.p = _context3.n) {
205
203
  case 0:
206
204
  setPasskeySignupError("");
207
205
  siteInfo = "".concat(new URL(window.location.href).hostname, " - ").concat(new Date().toLocaleString(undefined, {
@@ -214,12 +212,12 @@ var Auth = function Auth(_ref) {
214
212
  }));
215
213
  setPasskeySignupScreen(false);
216
214
  setPasskeyCreationScreen(true);
217
- _context3.prev = 4;
215
+ _context3.p = 1;
218
216
  if (passkeyCreated) {
219
- _context3.next = 22;
217
+ _context3.n = 6;
220
218
  break;
221
219
  }
222
- _context3.next = 8;
220
+ _context3.n = 2;
223
221
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.createUserPasskey({
224
222
  publicKey: {
225
223
  user: {
@@ -228,22 +226,22 @@ var Auth = function Auth(_ref) {
228
226
  }
229
227
  }
230
228
  });
231
- case 8:
232
- _context3.t0 = _context3.sent;
233
- if (_context3.t0) {
234
- _context3.next = 11;
229
+ case 2:
230
+ _t = _context3.v;
231
+ if (_t) {
232
+ _context3.n = 3;
235
233
  break;
236
234
  }
237
- _context3.t0 = {};
238
- case 11:
239
- _ref5 = _context3.t0;
235
+ _t = {};
236
+ case 3:
237
+ _ref5 = _t;
240
238
  encodedChallenge = _ref5.encodedChallenge;
241
239
  attestation = _ref5.attestation;
242
240
  if (!(encodedChallenge && attestation)) {
243
- _context3.next = 21;
241
+ _context3.n = 5;
244
242
  break;
245
243
  }
246
- _context3.next = 17;
244
+ _context3.n = 4;
247
245
  return server.createSuborg(_objectSpread2({
248
246
  email: email,
249
247
  passkey: {
@@ -254,108 +252,106 @@ var Auth = function Auth(_ref) {
254
252
  }, customAccounts && {
255
253
  customAccounts: customAccounts
256
254
  }));
257
- case 17:
258
- response = _context3.sent;
255
+ case 4:
256
+ response = _context3.v;
259
257
  if (response !== null && response !== void 0 && response.subOrganizationId) {
260
258
  setPasskeyCreated(true);
261
259
  }
262
- _context3.next = 22;
260
+ _context3.n = 6;
263
261
  break;
264
- case 21:
265
- case 22:
266
- _context3.next = 24;
262
+ case 5:
263
+ case 6:
264
+ _context3.n = 7;
267
265
  return indexedDbClient.resetKeyPair();
268
- case 24:
269
- _context3.next = 26;
266
+ case 7:
267
+ _context3.n = 8;
270
268
  return indexedDbClient.getPublicKey();
271
- case 26:
272
- pubKey = _context3.sent;
273
- _context3.next = 29;
269
+ case 8:
270
+ pubKey = _context3.v;
271
+ _context3.n = 9;
274
272
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.loginWithPasskey({
275
273
  sessionType: SessionType.READ_WRITE,
276
274
  publicKey: pubKey,
277
275
  expirationSeconds: (_authConfig$sessionLe = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe === void 0 ? void 0 : _authConfig$sessionLe.toString()
278
276
  });
279
- case 29:
280
- _context3.next = 31;
277
+ case 9:
278
+ _context3.n = 10;
281
279
  return onAuthSuccess();
282
- case 31:
283
- _context3.next = 37;
280
+ case 10:
281
+ _context3.n = 12;
284
282
  break;
285
- case 33:
286
- _context3.prev = 33;
287
- _context3.t1 = _context3["catch"](4);
283
+ case 11:
284
+ _context3.p = 11;
285
+ _t2 = _context3.v;
288
286
  setPasskeySignupError(authErrors.passkey.timeoutOrNotAllowed);
289
- console.error("Error during passkey signup: ", _context3.t1);
290
- case 37:
291
- case "end":
292
- return _context3.stop();
287
+ console.error("Error during passkey signup: ", _t2);
288
+ case 12:
289
+ return _context3.a(2);
293
290
  }
294
- }, _callee3, null, [[4, 33]]);
291
+ }, _callee3, null, [[1, 11]]);
295
292
  }));
296
293
  return function handleSignupWithPasskey() {
297
294
  return _ref4.apply(this, arguments);
298
295
  };
299
296
  }();
300
297
  var handleLoginWithPasskey = /*#__PURE__*/function () {
301
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
302
- var _authConfig$sessionLe2, pubKey;
303
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
304
- while (1) switch (_context4.prev = _context4.next) {
298
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
299
+ var _authConfig$sessionLe2, pubKey, _t3;
300
+ return _regenerator().w(function (_context4) {
301
+ while (1) switch (_context4.p = _context4.n) {
305
302
  case 0:
306
- _context4.prev = 0;
303
+ _context4.p = 0;
307
304
  setLoading("passkey");
308
- _context4.next = 4;
305
+ _context4.n = 1;
309
306
  return indexedDbClient === null || indexedDbClient === void 0 ? void 0 : indexedDbClient.resetKeyPair();
310
- case 4:
311
- _context4.next = 6;
307
+ case 1:
308
+ _context4.n = 2;
312
309
  return indexedDbClient.getPublicKey();
313
- case 6:
314
- pubKey = _context4.sent;
315
- _context4.next = 9;
310
+ case 2:
311
+ pubKey = _context4.v;
312
+ _context4.n = 3;
316
313
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.loginWithPasskey({
317
314
  sessionType: SessionType.READ_WRITE,
318
315
  publicKey: pubKey,
319
316
  expirationSeconds: (_authConfig$sessionLe2 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe2 === void 0 ? void 0 : _authConfig$sessionLe2.toString()
320
317
  });
321
- case 9:
322
- _context4.next = 11;
318
+ case 3:
319
+ _context4.n = 4;
323
320
  return onAuthSuccess();
324
- case 11:
325
- _context4.next = 17;
321
+ case 4:
322
+ _context4.n = 6;
326
323
  break;
327
- case 13:
328
- _context4.prev = 13;
329
- _context4.t0 = _context4["catch"](0);
324
+ case 5:
325
+ _context4.p = 5;
326
+ _t3 = _context4.v;
330
327
  onError(authErrors.passkey.loginFailed);
331
- console.error("Error during passkey login: ", _context4.t0);
332
- case 17:
333
- _context4.prev = 17;
328
+ console.error("Error during passkey login: ", _t3);
329
+ case 6:
330
+ _context4.p = 6;
334
331
  setLoading(undefined);
335
- return _context4.finish(17);
336
- case 20:
337
- case "end":
338
- return _context4.stop();
332
+ return _context4.f(6);
333
+ case 7:
334
+ return _context4.a(2);
339
335
  }
340
- }, _callee4, null, [[0, 13, 17, 20]]);
336
+ }, _callee4, null, [[0, 5, 6, 7]]);
341
337
  }));
342
338
  return function handleLoginWithPasskey() {
343
339
  return _ref6.apply(this, arguments);
344
340
  };
345
341
  }();
346
342
  var handleSendOtp = /*#__PURE__*/function () {
347
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(value, otpType) {
343
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(value, otpType) {
348
344
  var _otpConfig$otpLength, _otpConfig$alphanumer;
349
345
  var publicKey, initAuthResponse;
350
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
351
- while (1) switch (_context5.prev = _context5.next) {
346
+ return _regenerator().w(function (_context5) {
347
+ while (1) switch (_context5.n) {
352
348
  case 0:
353
349
  setLoading(otpType);
354
- _context5.next = 3;
350
+ _context5.n = 1;
355
351
  return indexedDbClient.getPublicKey();
356
- case 3:
357
- publicKey = _context5.sent;
358
- _context5.next = 6;
352
+ case 1:
353
+ publicKey = _context5.v;
354
+ _context5.n = 2;
359
355
  return server.sendOtp(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
360
356
  otpType: otpType,
361
357
  contact: value
@@ -370,8 +366,8 @@ var Auth = function Auth(_ref) {
370
366
  alphanumeric: (_otpConfig$alphanumer = otpConfig === null || otpConfig === void 0 ? void 0 : otpConfig.alphanumeric) !== null && _otpConfig$alphanumer !== void 0 ? _otpConfig$alphanumer : false,
371
367
  userIdentifier: publicKey
372
368
  }));
373
- case 6:
374
- initAuthResponse = _context5.sent;
369
+ case 2:
370
+ initAuthResponse = _context5.v;
375
371
  if (initAuthResponse && initAuthResponse.otpId) {
376
372
  setOtpId(initAuthResponse === null || initAuthResponse === void 0 ? void 0 : initAuthResponse.otpId);
377
373
  setStep(otpType);
@@ -379,9 +375,8 @@ var Auth = function Auth(_ref) {
379
375
  onError(authErrors.otp.sendFailed);
380
376
  }
381
377
  setLoading(undefined);
382
- case 9:
383
- case "end":
384
- return _context5.stop();
378
+ case 3:
379
+ return _context5.a(2);
385
380
  }
386
381
  }, _callee5);
387
382
  }));
@@ -390,7 +385,7 @@ var Auth = function Auth(_ref) {
390
385
  };
391
386
  }();
392
387
  var handleOAuthLogin = /*#__PURE__*/function () {
393
- var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(credential, providerName) {
388
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(credential, providerName) {
394
389
  var _yield$server$getSubo;
395
390
  var socialLinking,
396
391
  pubKey,
@@ -412,21 +407,36 @@ var Auth = function Auth(_ref) {
412
407
  userId,
413
408
  _yield$server$createS,
414
409
  _yield$server$createS2,
415
- _args7 = arguments;
416
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
417
- while (1) switch (_context7.prev = _context7.next) {
410
+ _args7 = arguments,
411
+ _t4,
412
+ _t5,
413
+ _t6,
414
+ _t7,
415
+ _t8,
416
+ _t9,
417
+ _t0,
418
+ _t1,
419
+ _t10,
420
+ _t11,
421
+ _t12,
422
+ _t13,
423
+ _t14,
424
+ _t15,
425
+ _t16;
426
+ return _regenerator().w(function (_context7) {
427
+ while (1) switch (_context7.n) {
418
428
  case 0:
419
429
  socialLinking = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : false;
420
- _context7.next = 3;
430
+ _context7.n = 1;
421
431
  return indexedDbClient === null || indexedDbClient === void 0 ? void 0 : indexedDbClient.getPublicKey();
422
- case 3:
423
- pubKey = _context7.sent;
432
+ case 1:
433
+ pubKey = _context7.v;
424
434
  if (pubKey) {
425
- _context7.next = 6;
435
+ _context7.n = 2;
426
436
  break;
427
437
  }
428
- return _context7.abrupt("return");
429
- case 6:
438
+ return _context7.a(2);
439
+ case 2:
430
440
  setOauthLoading(providerName);
431
441
  oauthProviders = [{
432
442
  providerName: providerName,
@@ -438,33 +448,32 @@ var Auth = function Auth(_ref) {
438
448
  customAccounts: customAccounts
439
449
  });
440
450
  completeLogin = /*#__PURE__*/function () {
441
- var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(suborgID) {
451
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(suborgID) {
442
452
  var sessionResponse;
443
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
444
- while (1) switch (_context6.prev = _context6.next) {
453
+ return _regenerator().w(function (_context6) {
454
+ while (1) switch (_context6.n) {
445
455
  case 0:
446
- _context6.next = 2;
456
+ _context6.n = 1;
447
457
  return server.oauthLogin({
448
458
  suborgID: suborgID,
449
459
  oidcToken: credential,
450
460
  publicKey: pubKey,
451
461
  sessionLengthSeconds: authConfig.sessionLengthSeconds
452
462
  });
453
- case 2:
454
- sessionResponse = _context6.sent;
463
+ case 1:
464
+ sessionResponse = _context6.v;
455
465
  if (!(sessionResponse !== null && sessionResponse !== void 0 && sessionResponse.session)) {
456
- _context6.next = 7;
466
+ _context6.n = 3;
457
467
  break;
458
468
  }
459
- _context6.next = 6;
469
+ _context6.n = 2;
460
470
  return indexedDbClient.loginWithSession(sessionResponse.session);
461
- case 6:
462
- return _context6.abrupt("return", onAuthSuccess());
463
- case 7:
471
+ case 2:
472
+ return _context6.a(2, onAuthSuccess());
473
+ case 3:
464
474
  onError(authErrors.oauth.loginFailed);
465
- case 8:
466
- case "end":
467
- return _context6.stop();
475
+ case 4:
476
+ return _context6.a(2);
468
477
  }
469
478
  }, _callee6);
470
479
  }));
@@ -473,54 +482,54 @@ var Auth = function Auth(_ref) {
473
482
  };
474
483
  }(); // Non-social-linking path: getOrCreateSuborg then login
475
484
  if (socialLinking) {
476
- _context7.next = 18;
485
+ _context7.n = 5;
477
486
  break;
478
487
  }
479
- _context7.next = 13;
488
+ _context7.n = 3;
480
489
  return server.getOrCreateSuborg({
481
490
  filterType: FilterType.OidcToken,
482
491
  filterValue: credential,
483
492
  additionalData: createSuborgData
484
493
  });
485
- case 13:
486
- resp = _context7.sent;
494
+ case 3:
495
+ resp = _context7.v;
487
496
  suborgIds = resp === null || resp === void 0 ? void 0 : resp.subOrganizationIds;
488
497
  if (suborgIds !== null && suborgIds !== void 0 && suborgIds.length) {
489
- _context7.next = 17;
498
+ _context7.n = 4;
490
499
  break;
491
500
  }
492
- return _context7.abrupt("return", onError(authErrors.oauth.loginFailed));
493
- case 17:
494
- return _context7.abrupt("return", completeLogin(suborgIds[0]));
495
- case 18:
496
- _context7.next = 20;
501
+ return _context7.a(2, onError(authErrors.oauth.loginFailed));
502
+ case 4:
503
+ return _context7.a(2, completeLogin(suborgIds[0]));
504
+ case 5:
505
+ _context7.n = 6;
497
506
  return server.getSuborgs({
498
507
  filterType: FilterType.OidcToken,
499
508
  filterValue: credential
500
509
  });
501
- case 20:
502
- _context7.t1 = _yield$server$getSubo = _context7.sent;
503
- _context7.t0 = _context7.t1 === null;
504
- if (_context7.t0) {
505
- _context7.next = 24;
510
+ case 6:
511
+ _t5 = _yield$server$getSubo = _context7.v;
512
+ _t4 = _t5 === null;
513
+ if (_t4) {
514
+ _context7.n = 7;
506
515
  break;
507
516
  }
508
- _context7.t0 = _yield$server$getSubo === void 0;
509
- case 24:
510
- if (!_context7.t0) {
511
- _context7.next = 28;
517
+ _t4 = _yield$server$getSubo === void 0;
518
+ case 7:
519
+ if (!_t4) {
520
+ _context7.n = 8;
512
521
  break;
513
522
  }
514
- _context7.t2 = void 0;
515
- _context7.next = 29;
523
+ _t6 = void 0;
524
+ _context7.n = 9;
516
525
  break;
517
- case 28:
518
- _context7.t2 = _yield$server$getSubo.organizationIds;
519
- case 29:
520
- oidcOrgIds = _context7.t2;
526
+ case 8:
527
+ _t6 = _yield$server$getSubo.organizationIds;
528
+ case 9:
529
+ oidcOrgIds = _t6;
521
530
  orgId = oidcOrgIds === null || oidcOrgIds === void 0 ? void 0 : oidcOrgIds[0]; // If not, try to link by verified email (Google only)
522
531
  if (orgId) {
523
- _context7.next = 93;
532
+ _context7.n = 31;
524
533
  break;
525
534
  }
526
535
  _ref0 = jwtDecode(credential) || {}, oidcEmail = _ref0.email, iss = _ref0.iss;
@@ -531,133 +540,130 @@ var Auth = function Auth(_ref) {
531
540
  customAccounts: customAccounts
532
541
  });
533
542
  if (!(oidcEmail && iss === "https://accounts.google.com")) {
534
- _context7.next = 81;
543
+ _context7.n = 26;
535
544
  break;
536
545
  }
537
- _context7.next = 37;
546
+ _context7.n = 10;
538
547
  return server.getVerifiedSuborgs({
539
548
  filterType: FilterType.Email,
540
549
  filterValue: oidcEmail
541
550
  });
542
- case 37:
543
- _context7.t4 = _yield$server$getVeri = _context7.sent;
544
- _context7.t3 = _context7.t4 === null;
545
- if (_context7.t3) {
546
- _context7.next = 41;
551
+ case 10:
552
+ _t8 = _yield$server$getVeri = _context7.v;
553
+ _t7 = _t8 === null;
554
+ if (_t7) {
555
+ _context7.n = 11;
547
556
  break;
548
557
  }
549
- _context7.t3 = _yield$server$getVeri === void 0;
550
- case 41:
551
- if (!_context7.t3) {
552
- _context7.next = 45;
558
+ _t7 = _yield$server$getVeri === void 0;
559
+ case 11:
560
+ if (!_t7) {
561
+ _context7.n = 12;
553
562
  break;
554
563
  }
555
- _context7.t5 = void 0;
556
- _context7.next = 46;
564
+ _t9 = void 0;
565
+ _context7.n = 13;
557
566
  break;
558
- case 45:
559
- _context7.t5 = _yield$server$getVeri.organizationIds;
560
- case 46:
561
- emailOrgIds = _context7.t5;
567
+ case 12:
568
+ _t9 = _yield$server$getVeri.organizationIds;
569
+ case 13:
570
+ emailOrgIds = _t9;
562
571
  if (!(emailOrgIds !== null && emailOrgIds !== void 0 && emailOrgIds[0])) {
563
- _context7.next = 67;
572
+ _context7.n = 20;
564
573
  break;
565
574
  }
566
575
  orgId = emailOrgIds[0];
567
576
  // attach this new OIDC provider to the existing user
568
- _context7.next = 51;
577
+ _context7.n = 14;
569
578
  return server.getUsers({
570
579
  organizationId: orgId
571
580
  });
572
- case 51:
573
- _context7.t7 = _yield$server$getUser = _context7.sent;
574
- _context7.t6 = _context7.t7 === null;
575
- if (_context7.t6) {
576
- _context7.next = 55;
581
+ case 14:
582
+ _t1 = _yield$server$getUser = _context7.v;
583
+ _t0 = _t1 === null;
584
+ if (_t0) {
585
+ _context7.n = 15;
577
586
  break;
578
587
  }
579
- _context7.t6 = _yield$server$getUser === void 0;
580
- case 55:
581
- if (!_context7.t6) {
582
- _context7.next = 59;
588
+ _t0 = _yield$server$getUser === void 0;
589
+ case 15:
590
+ if (!_t0) {
591
+ _context7.n = 16;
583
592
  break;
584
593
  }
585
- _context7.t8 = void 0;
586
- _context7.next = 60;
594
+ _t10 = void 0;
595
+ _context7.n = 17;
587
596
  break;
588
- case 59:
589
- _context7.t8 = (_yield$server$getUser2 = _yield$server$getUser.users) === null || _yield$server$getUser2 === void 0 ? void 0 : (_yield$server$getUser3 = _yield$server$getUser2[0]) === null || _yield$server$getUser3 === void 0 ? void 0 : _yield$server$getUser3.userId;
590
- case 60:
591
- userId = _context7.t8;
597
+ case 16:
598
+ _t10 = (_yield$server$getUser2 = _yield$server$getUser.users) === null || _yield$server$getUser2 === void 0 ? void 0 : (_yield$server$getUser3 = _yield$server$getUser2[0]) === null || _yield$server$getUser3 === void 0 ? void 0 : _yield$server$getUser3.userId;
599
+ case 17:
600
+ userId = _t10;
592
601
  if (userId) {
593
- _context7.next = 63;
602
+ _context7.n = 18;
594
603
  break;
595
604
  }
596
- return _context7.abrupt("return", onError(authErrors.oauth.loginFailed));
597
- case 63:
598
- _context7.next = 65;
605
+ return _context7.a(2, onError(authErrors.oauth.loginFailed));
606
+ case 18:
607
+ _context7.n = 19;
599
608
  return server.createOauthProviders({
600
609
  organizationId: orgId,
601
610
  userId: userId,
602
611
  oauthProviders: oauthProviders
603
612
  });
604
- case 65:
605
- _context7.next = 79;
613
+ case 19:
614
+ _context7.n = 25;
606
615
  break;
607
- case 67:
608
- _context7.next = 69;
616
+ case 20:
617
+ _context7.n = 21;
609
618
  return server.createSuborg(createSuborgData);
610
- case 69:
611
- _context7.t10 = _yield$server$createS = _context7.sent;
612
- _context7.t9 = _context7.t10 === null;
613
- if (_context7.t9) {
614
- _context7.next = 73;
619
+ case 21:
620
+ _t12 = _yield$server$createS = _context7.v;
621
+ _t11 = _t12 === null;
622
+ if (_t11) {
623
+ _context7.n = 22;
615
624
  break;
616
625
  }
617
- _context7.t9 = _yield$server$createS === void 0;
618
- case 73:
619
- if (!_context7.t9) {
620
- _context7.next = 77;
626
+ _t11 = _yield$server$createS === void 0;
627
+ case 22:
628
+ if (!_t11) {
629
+ _context7.n = 23;
621
630
  break;
622
631
  }
623
- _context7.t11 = void 0;
624
- _context7.next = 78;
632
+ _t13 = void 0;
633
+ _context7.n = 24;
625
634
  break;
626
- case 77:
627
- _context7.t11 = _yield$server$createS.subOrganizationId;
628
- case 78:
629
- orgId = _context7.t11;
630
- case 79:
631
- _context7.next = 93;
635
+ case 23:
636
+ _t13 = _yield$server$createS.subOrganizationId;
637
+ case 24:
638
+ orgId = _t13;
639
+ case 25:
640
+ _context7.n = 31;
632
641
  break;
633
- case 81:
634
- _context7.next = 83;
642
+ case 26:
643
+ _context7.n = 27;
635
644
  return server.createSuborg(createSuborgData);
636
- case 83:
637
- _context7.t13 = _yield$server$createS2 = _context7.sent;
638
- _context7.t12 = _context7.t13 === null;
639
- if (_context7.t12) {
640
- _context7.next = 87;
645
+ case 27:
646
+ _t15 = _yield$server$createS2 = _context7.v;
647
+ _t14 = _t15 === null;
648
+ if (_t14) {
649
+ _context7.n = 28;
641
650
  break;
642
651
  }
643
- _context7.t12 = _yield$server$createS2 === void 0;
644
- case 87:
645
- if (!_context7.t12) {
646
- _context7.next = 91;
652
+ _t14 = _yield$server$createS2 === void 0;
653
+ case 28:
654
+ if (!_t14) {
655
+ _context7.n = 29;
647
656
  break;
648
657
  }
649
- _context7.t14 = void 0;
650
- _context7.next = 92;
658
+ _t16 = void 0;
659
+ _context7.n = 30;
651
660
  break;
652
- case 91:
653
- _context7.t14 = _yield$server$createS2.subOrganizationId;
654
- case 92:
655
- orgId = _context7.t14;
656
- case 93:
657
- return _context7.abrupt("return", orgId ? completeLogin(orgId) : onError(authErrors.oauth.loginFailed));
658
- case 94:
659
- case "end":
660
- return _context7.stop();
661
+ case 29:
662
+ _t16 = _yield$server$createS2.subOrganizationId;
663
+ case 30:
664
+ orgId = _t16;
665
+ case 31:
666
+ return _context7.a(2, orgId ? completeLogin(orgId) : onError(authErrors.oauth.loginFailed));
661
667
  }
662
668
  }, _callee7);
663
669
  }));
@@ -666,31 +672,31 @@ var Auth = function Auth(_ref) {
666
672
  };
667
673
  }();
668
674
  var handleLoginWithWallet = /*#__PURE__*/function () {
669
- var _ref1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
670
- var _authConfig$sessionLe3, publicKey, _walletClient$getWall, type, resp, suborgIds, pubKey;
671
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
672
- while (1) switch (_context8.prev = _context8.next) {
675
+ var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
676
+ var _authConfig$sessionLe3, publicKey, _walletClient$getWall, type, resp, suborgIds, pubKey, _t17;
677
+ return _regenerator().w(function (_context8) {
678
+ while (1) switch (_context8.p = _context8.n) {
673
679
  case 0:
674
680
  setLoading("wallet");
675
- _context8.prev = 1;
681
+ _context8.p = 1;
676
682
  if (walletClient) {
677
- _context8.next = 4;
683
+ _context8.n = 2;
678
684
  break;
679
685
  }
680
686
  throw new Error("Wallet client not initialized");
681
- case 4:
682
- _context8.next = 6;
687
+ case 2:
688
+ _context8.n = 3;
683
689
  return walletClient.getPublicKey();
684
- case 6:
685
- publicKey = _context8.sent;
690
+ case 3:
691
+ publicKey = _context8.v;
686
692
  if (publicKey) {
687
- _context8.next = 9;
693
+ _context8.n = 4;
688
694
  break;
689
695
  }
690
696
  throw new Error(authErrors.wallet.noPublicKey);
691
- case 9:
697
+ case 4:
692
698
  _walletClient$getWall = walletClient.getWalletInterface(), type = _walletClient$getWall.type;
693
- _context8.next = 12;
699
+ _context8.n = 5;
694
700
  return server.getOrCreateSuborg(_objectSpread2({
695
701
  filterType: FilterType.PublicKey,
696
702
  filterValue: publicKey,
@@ -703,49 +709,48 @@ var Auth = function Auth(_ref) {
703
709
  }, customAccounts && {
704
710
  customAccounts: customAccounts
705
711
  }));
706
- case 12:
707
- resp = _context8.sent;
712
+ case 5:
713
+ resp = _context8.v;
708
714
  suborgIds = resp === null || resp === void 0 ? void 0 : resp.subOrganizationIds;
709
715
  if (!(!suborgIds || suborgIds.length === 0)) {
710
- _context8.next = 17;
716
+ _context8.n = 6;
711
717
  break;
712
718
  }
713
719
  onError(authErrors.wallet.loginFailed);
714
- return _context8.abrupt("return");
715
- case 17:
716
- _context8.next = 19;
720
+ return _context8.a(2);
721
+ case 6:
722
+ _context8.n = 7;
717
723
  return indexedDbClient.resetKeyPair();
718
- case 19:
719
- _context8.next = 21;
724
+ case 7:
725
+ _context8.n = 8;
720
726
  return indexedDbClient.getPublicKey();
721
- case 21:
722
- pubKey = _context8.sent;
723
- _context8.next = 24;
727
+ case 8:
728
+ pubKey = _context8.v;
729
+ _context8.n = 9;
724
730
  return walletClient.loginWithWallet({
725
731
  sessionType: SessionType.READ_WRITE,
726
732
  publicKey: pubKey,
727
733
  expirationSeconds: (_authConfig$sessionLe3 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe3 === void 0 ? void 0 : _authConfig$sessionLe3.toString()
728
734
  });
729
- case 24:
730
- _context8.next = 26;
735
+ case 9:
736
+ _context8.n = 10;
731
737
  return onAuthSuccess();
732
- case 26:
733
- _context8.next = 32;
738
+ case 10:
739
+ _context8.n = 12;
734
740
  break;
735
- case 28:
736
- _context8.prev = 28;
737
- _context8.t0 = _context8["catch"](1);
738
- onError(_context8.t0.message || authErrors.wallet.loginFailed);
739
- console.error("Error during wallet login: ", _context8.t0);
740
- case 32:
741
- _context8.prev = 32;
741
+ case 11:
742
+ _context8.p = 11;
743
+ _t17 = _context8.v;
744
+ onError(_t17.message || authErrors.wallet.loginFailed);
745
+ console.error("Error during wallet login: ", _t17);
746
+ case 12:
747
+ _context8.p = 12;
742
748
  setLoading(undefined);
743
- return _context8.finish(32);
744
- case 35:
745
- case "end":
746
- return _context8.stop();
749
+ return _context8.f(12);
750
+ case 13:
751
+ return _context8.a(2);
747
752
  }
748
- }, _callee8, null, [[1, 28, 32, 35]]);
753
+ }, _callee8, null, [[1, 11, 12, 13]]);
749
754
  }));
750
755
  return function handleLoginWithWallet() {
751
756
  return _ref1.apply(this, arguments);