@vunexa/lixa 0.1.6-alpha.15 → 0.1.6-alpha.16

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.
@@ -1305,6 +1305,7 @@ export declare class Lixa<TIdentity extends IIdentityProvider | IdentityConfig =
1305
1305
  private userResourceStore;
1306
1306
  private userAccountStore;
1307
1307
  private refreshMutexes;
1308
+ private linkingChallenges;
1308
1309
  private identityProvider?;
1309
1310
  private credentialsManager?;
1310
1311
  private config;
package/dist/index.cjs CHANGED
@@ -1460,6 +1460,7 @@ var Lixa = class _Lixa {
1460
1460
  userResourceStore = /* @__PURE__ */ new Map();
1461
1461
  userAccountStore = /* @__PURE__ */ new Map();
1462
1462
  refreshMutexes = /* @__PURE__ */ new Map();
1463
+ linkingChallenges = /* @__PURE__ */ new Map();
1463
1464
  identityProvider;
1464
1465
  credentialsManager;
1465
1466
  config;
@@ -2225,13 +2226,9 @@ var Lixa = class _Lixa {
2225
2226
  }
2226
2227
  }
2227
2228
  const challengeToken = (0, import_crypto5.randomBytes)(24).toString("hex");
2228
- const stateStorage2 = this.stateHandler.stateStorage || this.localStateHandler.stateStorage;
2229
- await stateStorage2.saveState(
2230
- `linking_challenge:${challengeToken}`,
2231
- {
2229
+ this.linkingChallenges.set(challengeToken, {
2230
+ data: {
2232
2231
  provider: providerType,
2233
- codeVerifier: "",
2234
- createdAt: Date.now(),
2235
2232
  challengeToken,
2236
2233
  email,
2237
2234
  incomingProvider: providerType,
@@ -2241,8 +2238,8 @@ var Lixa = class _Lixa {
2241
2238
  hasPassword,
2242
2239
  tokens
2243
2240
  },
2244
- 600
2245
- );
2241
+ expiresAt: Date.now() + 6e5
2242
+ });
2246
2243
  this.log(
2247
2244
  "WARN",
2248
2245
  "AccountLinking",
@@ -2432,9 +2429,15 @@ var Lixa = class _Lixa {
2432
2429
  */
2433
2430
  async confirmLinkingWithPassword(params) {
2434
2431
  const { challengeToken, password } = params;
2435
- const stateStorage = this.stateHandler.stateStorage || this.localStateHandler.stateStorage;
2436
- const stateKey = `linking_challenge:${challengeToken}`;
2437
- const cached = await stateStorage.getState(stateKey);
2432
+ const challenge = this.linkingChallenges.get(challengeToken);
2433
+ let cached = null;
2434
+ if (challenge && challenge.expiresAt >= Date.now()) {
2435
+ cached = challenge.data;
2436
+ } else {
2437
+ const stateStorage = this.stateHandler.stateStorage || this.localStateHandler.stateStorage;
2438
+ const stateKey = `linking_challenge:${challengeToken}`;
2439
+ cached = await stateStorage.getState(stateKey);
2440
+ }
2438
2441
  if (!cached || !cached.challengeToken) {
2439
2442
  throw new InvalidStateError("Invalid or expired account linking challenge.");
2440
2443
  }
@@ -2463,7 +2466,7 @@ var Lixa = class _Lixa {
2463
2466
  if (!verifiedUser) {
2464
2467
  throw new InvalidCredentialsError("Invalid password for account linking verification.");
2465
2468
  }
2466
- await stateStorage.deleteState(stateKey);
2469
+ this.linkingChallenges.delete(challengeToken);
2467
2470
  const providerType = String(cached.incomingProvider).toLowerCase();
2468
2471
  const incomingTokens = cached.tokens;
2469
2472
  const linkedAcc = {