@explorins/pers-signer 1.0.31 → 1.0.32

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.
package/dist/index.esm.js CHANGED
@@ -392,7 +392,7 @@ class AuthenticationService {
392
392
  async combinedAuthentication(identifier, persAccessToken) {
393
393
  try {
394
394
  // Step 1: Try to login with PERS token first (this will get signer JWT if user exists)
395
- let signerToken;
395
+ let signerToken = null;
396
396
  try {
397
397
  const loginResult = await this.loginWithPersToken(persAccessToken);
398
398
  // Extract token from login result
@@ -406,6 +406,11 @@ class AuthenticationService {
406
406
  catch (loginError) {
407
407
  // Step 2: User doesn't exist - register with v1 API (Unified Flow)
408
408
  try {
409
+ // Only proceed to registration if the error is explicitly 'user_not_found'
410
+ const errorMessage = loginError instanceof Error ? loginError.message : String(loginError);
411
+ if (errorMessage !== 'user_not_found') {
412
+ throw loginError;
413
+ }
409
414
  const registerResult = await this.registerUser(persAccessToken);
410
415
  if (registerResult && registerResult.access_token) {
411
416
  signerToken = registerResult.access_token;
@@ -416,9 +421,13 @@ class AuthenticationService {
416
421
  }
417
422
  catch (registerError) {
418
423
  console.error(`[AuthenticationService] Registration failed for ${identifier}:`, registerError);
424
+ // Explicitly rethrow to abort the entire authentication process
419
425
  throw registerError;
420
426
  }
421
427
  }
428
+ if (!signerToken) {
429
+ throw new Error('Authentication failed: Unable to obtain signer token');
430
+ }
422
431
  const user = {
423
432
  identifier: identifier,
424
433
  signerAuthToken: signerToken,
@@ -428,8 +437,9 @@ class AuthenticationService {
428
437
  return user;
429
438
  }
430
439
  catch (error) {
431
- console.error(`[PersSignerSDK] Combined authentication failed for ${identifier}:`, error);
432
- throw new Error(`Combined authentication failed: ${error}`);
440
+ const errorMessage = error instanceof Error ? error.message : String(error);
441
+ console.error(`[PersSignerSDK] Combined authentication failed for ${identifier}:`, errorMessage);
442
+ throw new Error(`Combined authentication failed: ${errorMessage}`);
433
443
  }
434
444
  }
435
445
  }