@turnkey/sdk-react 5.0.0 → 5.0.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.
@@ -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,48 @@ 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 session, 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 = 11;
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 turnkey.getSession();
166
+ case 3:
167
+ session = _context2.sent;
168
+ if (session) {
169
+ _context2.next = 7;
170
+ break;
171
+ }
172
+ _context2.next = 7;
173
+ return indexedDbClient.resetKeyPair();
174
+ case 7:
175
+ _context2.next = 9;
176
+ return indexedDbClient.getPublicKey();
177
+ case 9:
178
+ retrievedPublicKey = _context2.sent;
179
+ if (retrievedPublicKey) {
180
+ setComponentReady(true);
181
+ } else {
182
+ onError("Failed to retrieve public key.");
183
+ }
184
+ case 11:
185
+ case "end":
186
+ return _context2.stop();
187
+ }
188
+ }, _callee2);
189
+ }));
190
+ return function manageClient() {
191
+ return _ref3.apply(this, arguments);
192
+ };
193
+ }();
194
+ manageClient();
195
+ }, [indexedDbClient, turnkey]);
203
196
  if (!componentReady) {
204
197
  return jsx("div", {
205
198
  className: styles.defaultLoader,
@@ -415,10 +408,20 @@ var Auth = function Auth(_ref) {
415
408
  }();
416
409
  var handleOAuthLogin = /*#__PURE__*/function () {
417
410
  var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(credential, providerName) {
418
- var createSuborgData, resp, suborgIds, suborgId, sessionResponse;
411
+ var pubKey, createSuborgData, resp, suborgIds, suborgId, sessionResponse;
419
412
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
420
413
  while (1) switch (_context6.prev = _context6.next) {
421
414
  case 0:
415
+ _context6.next = 2;
416
+ return indexedDbClient === null || indexedDbClient === void 0 ? void 0 : indexedDbClient.getPublicKey();
417
+ case 2:
418
+ pubKey = _context6.sent;
419
+ if (pubKey) {
420
+ _context6.next = 5;
421
+ break;
422
+ }
423
+ return _context6.abrupt("return");
424
+ case 5:
422
425
  setOauthLoading(providerName);
423
426
  createSuborgData = {
424
427
  oauthProviders: [{
@@ -429,47 +432,47 @@ var Auth = function Auth(_ref) {
429
432
  if (customAccounts) {
430
433
  createSuborgData.customAccounts = customAccounts;
431
434
  }
432
- _context6.next = 5;
435
+ _context6.next = 10;
433
436
  return server.getOrCreateSuborg({
434
437
  filterType: FilterType.OidcToken,
435
438
  filterValue: credential,
436
439
  additionalData: createSuborgData
437
440
  });
438
- case 5:
441
+ case 10:
439
442
  resp = _context6.sent;
440
443
  suborgIds = resp === null || resp === void 0 ? void 0 : resp.subOrganizationIds;
441
444
  if (!(!suborgIds || suborgIds.length === 0)) {
442
- _context6.next = 10;
445
+ _context6.next = 15;
443
446
  break;
444
447
  }
445
448
  onError(authErrors.oauth.loginFailed);
446
449
  return _context6.abrupt("return");
447
- case 10:
450
+ case 15:
448
451
  suborgId = suborgIds[0];
449
- _context6.next = 13;
452
+ _context6.next = 18;
450
453
  return server.oauthLogin({
451
454
  suborgID: suborgId,
452
455
  oidcToken: credential,
453
- publicKey: publicKey,
456
+ publicKey: pubKey,
454
457
  sessionLengthSeconds: authConfig.sessionLengthSeconds
455
458
  });
456
- case 13:
459
+ case 18:
457
460
  sessionResponse = _context6.sent;
458
461
  if (!(sessionResponse && sessionResponse.session)) {
459
- _context6.next = 21;
462
+ _context6.next = 26;
460
463
  break;
461
464
  }
462
- _context6.next = 17;
465
+ _context6.next = 22;
463
466
  return indexedDbClient.loginWithSession(sessionResponse.session);
464
- case 17:
465
- _context6.next = 19;
467
+ case 22:
468
+ _context6.next = 24;
466
469
  return onAuthSuccess();
467
- case 19:
468
- _context6.next = 22;
470
+ case 24:
471
+ _context6.next = 27;
469
472
  break;
470
- case 21:
473
+ case 26:
471
474
  onError(authErrors.oauth.loginFailed);
472
- case 22:
475
+ case 27:
473
476
  case "end":
474
477
  return _context6.stop();
475
478
  }
@@ -481,7 +484,7 @@ var Auth = function Auth(_ref) {
481
484
  }();
482
485
  var handleLoginWithWallet = /*#__PURE__*/function () {
483
486
  var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
484
- var _authConfig$sessionLe3, _publicKey3, _walletClient$getWall, type, resp, suborgIds, pubKey;
487
+ var _authConfig$sessionLe3, publicKey, _walletClient$getWall, type, resp, suborgIds, pubKey;
485
488
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
486
489
  while (1) switch (_context7.prev = _context7.next) {
487
490
  case 0:
@@ -496,8 +499,8 @@ var Auth = function Auth(_ref) {
496
499
  _context7.next = 6;
497
500
  return walletClient.getPublicKey();
498
501
  case 6:
499
- _publicKey3 = _context7.sent;
500
- if (_publicKey3) {
502
+ publicKey = _context7.sent;
503
+ if (publicKey) {
501
504
  _context7.next = 9;
502
505
  break;
503
506
  }
@@ -507,10 +510,10 @@ var Auth = function Auth(_ref) {
507
510
  _context7.next = 12;
508
511
  return server.getOrCreateSuborg({
509
512
  filterType: FilterType.PublicKey,
510
- filterValue: _publicKey3,
513
+ filterValue: publicKey,
511
514
  additionalData: {
512
515
  wallet: {
513
- publicKey: _publicKey3,
516
+ publicKey: publicKey,
514
517
  type: type
515
518
  }
516
519
  }
@@ -594,14 +597,12 @@ var Auth = function Auth(_ref) {
594
597
  layout: layout,
595
598
  clientId: (_authConfig$googleCli = authConfig.googleClientId) !== null && _authConfig$googleCli !== void 0 ? _authConfig$googleCli : process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID,
596
599
  openInPage: authConfig.openOAuthInPage,
597
- publicKey: publicKey,
598
600
  onSuccess: function onSuccess(response) {
599
601
  return handleOAuthLogin(response.idToken, "Google");
600
602
  }
601
603
  }), appleEnabled && jsx(AppleAuthButton, {
602
604
  layout: layout,
603
605
  clientId: (_authConfig$appleClie = authConfig.appleClientId) !== null && _authConfig$appleClie !== void 0 ? _authConfig$appleClie : process.env.NEXT_PUBLIC_APPLE_CLIENT_ID,
604
- publicKey: publicKey,
605
606
  openInPage: authConfig.openOAuthInPage,
606
607
  onSuccess: function onSuccess(response) {
607
608
  return handleOAuthLogin(response.idToken, "Apple");
@@ -609,7 +610,6 @@ var Auth = function Auth(_ref) {
609
610
  }), facebookEnabled && jsx(FacebookAuthButton, {
610
611
  layout: layout,
611
612
  clientId: (_authConfig$facebookC = authConfig.facebookClientId) !== null && _authConfig$facebookC !== void 0 ? _authConfig$facebookC : process.env.NEXT_PUBLIC_FACEBOOK_CLIENT_ID,
612
- publicKey: publicKey,
613
613
  openInPage: authConfig.openOAuthInPage,
614
614
  onSuccess: function onSuccess(response) {
615
615
  return handleOAuthLogin(response.id_token, "Facebook");