@turnkey/sdk-react 5.0.1 → 5.1.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.
@@ -18,12 +18,8 @@ import { useTurnkey } from '../../hooks/use-turnkey.mjs';
18
18
  import { OtpType, FilterType, authErrors } from './constants.mjs';
19
19
  import { server } from '@turnkey/sdk-server';
20
20
  import parsePhoneNumberFromString from 'libphonenumber-js';
21
+ import { SessionType } from '@turnkey/sdk-types';
21
22
 
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 = {}));
27
23
  var passkeyIcon = jsxs("svg", {
28
24
  xmlns: "http://www.w3.org/2000/svg",
29
25
  width: "43",
@@ -153,35 +149,24 @@ var Auth = function Auth(_ref) {
153
149
  useEffect(function () {
154
150
  var manageClient = /*#__PURE__*/function () {
155
151
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
156
- var session, retrievedPublicKey;
152
+ var retrievedPublicKey;
157
153
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
158
154
  while (1) switch (_context2.prev = _context2.next) {
159
155
  case 0:
160
156
  if (!(indexedDbClient && turnkey)) {
161
- _context2.next = 11;
157
+ _context2.next = 5;
162
158
  break;
163
159
  }
164
160
  _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
161
  return indexedDbClient.getPublicKey();
177
- case 9:
162
+ case 3:
178
163
  retrievedPublicKey = _context2.sent;
179
164
  if (retrievedPublicKey) {
180
165
  setComponentReady(true);
181
166
  } else {
182
167
  onError("Failed to retrieve public key.");
183
168
  }
184
- case 11:
169
+ case 5:
185
170
  case "end":
186
171
  return _context2.stop();
187
172
  }
@@ -278,31 +263,34 @@ var Auth = function Auth(_ref) {
278
263
  case 21:
279
264
  case 22:
280
265
  _context3.next = 24;
281
- return indexedDbClient.getPublicKey();
266
+ return indexedDbClient.resetKeyPair();
282
267
  case 24:
268
+ _context3.next = 26;
269
+ return indexedDbClient.getPublicKey();
270
+ case 26:
283
271
  pubKey = _context3.sent;
284
- _context3.next = 27;
272
+ _context3.next = 29;
285
273
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.loginWithPasskey({
286
274
  sessionType: SessionType.READ_WRITE,
287
275
  publicKey: pubKey,
288
276
  expirationSeconds: (_authConfig$sessionLe = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe === void 0 ? void 0 : _authConfig$sessionLe.toString()
289
277
  });
290
- case 27:
291
- _context3.next = 29;
292
- return onAuthSuccess();
293
278
  case 29:
294
- _context3.next = 35;
295
- break;
279
+ _context3.next = 31;
280
+ return onAuthSuccess();
296
281
  case 31:
297
- _context3.prev = 31;
282
+ _context3.next = 37;
283
+ break;
284
+ case 33:
285
+ _context3.prev = 33;
298
286
  _context3.t1 = _context3["catch"](4);
299
287
  setPasskeySignupError(authErrors.passkey.timeoutOrNotAllowed);
300
288
  console.error("Error during passkey signup: ", _context3.t1);
301
- case 35:
289
+ case 37:
302
290
  case "end":
303
291
  return _context3.stop();
304
292
  }
305
- }, _callee3, null, [[4, 31]]);
293
+ }, _callee3, null, [[4, 33]]);
306
294
  }));
307
295
  return function handleSignupWithPasskey() {
308
296
  return _ref4.apply(this, arguments);
@@ -317,35 +305,38 @@ var Auth = function Auth(_ref) {
317
305
  _context4.prev = 0;
318
306
  setLoading("passkey");
319
307
  _context4.next = 4;
320
- return indexedDbClient.getPublicKey();
308
+ return indexedDbClient === null || indexedDbClient === void 0 ? void 0 : indexedDbClient.resetKeyPair();
321
309
  case 4:
310
+ _context4.next = 6;
311
+ return indexedDbClient.getPublicKey();
312
+ case 6:
322
313
  pubKey = _context4.sent;
323
- _context4.next = 7;
314
+ _context4.next = 9;
324
315
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.loginWithPasskey({
325
316
  sessionType: SessionType.READ_WRITE,
326
317
  publicKey: pubKey,
327
318
  expirationSeconds: (_authConfig$sessionLe2 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe2 === void 0 ? void 0 : _authConfig$sessionLe2.toString()
328
319
  });
329
- case 7:
330
- _context4.next = 9;
331
- return onAuthSuccess();
332
320
  case 9:
333
- _context4.next = 15;
334
- break;
321
+ _context4.next = 11;
322
+ return onAuthSuccess();
335
323
  case 11:
336
- _context4.prev = 11;
324
+ _context4.next = 17;
325
+ break;
326
+ case 13:
327
+ _context4.prev = 13;
337
328
  _context4.t0 = _context4["catch"](0);
338
329
  onError(authErrors.passkey.loginFailed);
339
330
  console.error("Error during passkey login: ", _context4.t0);
340
- case 15:
341
- _context4.prev = 15;
331
+ case 17:
332
+ _context4.prev = 17;
342
333
  setLoading(undefined);
343
- return _context4.finish(15);
344
- case 18:
334
+ return _context4.finish(17);
335
+ case 20:
345
336
  case "end":
346
337
  return _context4.stop();
347
338
  }
348
- }, _callee4, null, [[0, 11, 15, 18]]);
339
+ }, _callee4, null, [[0, 13, 17, 20]]);
349
340
  }));
350
341
  return function handleLoginWithPasskey() {
351
342
  return _ref6.apply(this, arguments);
@@ -529,35 +520,38 @@ var Auth = function Auth(_ref) {
529
520
  return _context7.abrupt("return");
530
521
  case 17:
531
522
  _context7.next = 19;
532
- return indexedDbClient.getPublicKey();
523
+ return indexedDbClient.resetKeyPair();
533
524
  case 19:
525
+ _context7.next = 21;
526
+ return indexedDbClient.getPublicKey();
527
+ case 21:
534
528
  pubKey = _context7.sent;
535
- _context7.next = 22;
529
+ _context7.next = 24;
536
530
  return walletClient.loginWithWallet({
537
531
  sessionType: SessionType.READ_WRITE,
538
532
  publicKey: pubKey,
539
533
  expirationSeconds: (_authConfig$sessionLe3 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe3 === void 0 ? void 0 : _authConfig$sessionLe3.toString()
540
534
  });
541
- case 22:
542
- _context7.next = 24;
543
- return onAuthSuccess();
544
535
  case 24:
545
- _context7.next = 30;
546
- break;
536
+ _context7.next = 26;
537
+ return onAuthSuccess();
547
538
  case 26:
548
- _context7.prev = 26;
539
+ _context7.next = 32;
540
+ break;
541
+ case 28:
542
+ _context7.prev = 28;
549
543
  _context7.t0 = _context7["catch"](1);
550
544
  onError(_context7.t0.message || authErrors.wallet.loginFailed);
551
545
  console.error("Error during wallet login: ", _context7.t0);
552
- case 30:
553
- _context7.prev = 30;
546
+ case 32:
547
+ _context7.prev = 32;
554
548
  setLoading(undefined);
555
- return _context7.finish(30);
556
- case 33:
549
+ return _context7.finish(32);
550
+ case 35:
557
551
  case "end":
558
552
  return _context7.stop();
559
553
  }
560
- }, _callee7, null, [[1, 26, 30, 33]]);
554
+ }, _callee7, null, [[1, 28, 32, 35]]);
561
555
  }));
562
556
  return function handleLoginWithWallet() {
563
557
  return _ref9.apply(this, arguments);
@@ -884,5 +878,5 @@ var Auth = function Auth(_ref) {
884
878
  });
885
879
  };
886
880
 
887
- export { SessionType, Auth as default };
881
+ export { Auth as default };
888
882
  //# sourceMappingURL=Auth.mjs.map