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