@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.
@@ -1598,7 +1598,7 @@ class AuthenticationService {
1598
1598
  async combinedAuthentication(identifier, persAccessToken) {
1599
1599
  try {
1600
1600
  // Step 1: Try to login with PERS token first (this will get signer JWT if user exists)
1601
- let signerToken;
1601
+ let signerToken = null;
1602
1602
  try {
1603
1603
  const loginResult = await this.loginWithPersToken(persAccessToken);
1604
1604
  // Extract token from login result
@@ -1612,6 +1612,11 @@ class AuthenticationService {
1612
1612
  catch (loginError) {
1613
1613
  // Step 2: User doesn't exist - register with v1 API (Unified Flow)
1614
1614
  try {
1615
+ // Only proceed to registration if the error is explicitly 'user_not_found'
1616
+ const errorMessage = loginError instanceof Error ? loginError.message : String(loginError);
1617
+ if (errorMessage !== 'user_not_found') {
1618
+ throw loginError;
1619
+ }
1615
1620
  const registerResult = await this.registerUser(persAccessToken);
1616
1621
  if (registerResult && registerResult.access_token) {
1617
1622
  signerToken = registerResult.access_token;
@@ -1622,9 +1627,13 @@ class AuthenticationService {
1622
1627
  }
1623
1628
  catch (registerError) {
1624
1629
  console.error(`[AuthenticationService] Registration failed for ${identifier}:`, registerError);
1630
+ // Explicitly rethrow to abort the entire authentication process
1625
1631
  throw registerError;
1626
1632
  }
1627
1633
  }
1634
+ if (!signerToken) {
1635
+ throw new Error('Authentication failed: Unable to obtain signer token');
1636
+ }
1628
1637
  const user = {
1629
1638
  identifier: identifier,
1630
1639
  signerAuthToken: signerToken,
@@ -1634,8 +1643,9 @@ class AuthenticationService {
1634
1643
  return user;
1635
1644
  }
1636
1645
  catch (error) {
1637
- console.error(`[PersSignerSDK] Combined authentication failed for ${identifier}:`, error);
1638
- throw new Error(`Combined authentication failed: ${error}`);
1646
+ const errorMessage = error instanceof Error ? error.message : String(error);
1647
+ console.error(`[PersSignerSDK] Combined authentication failed for ${identifier}:`, errorMessage);
1648
+ throw new Error(`Combined authentication failed: ${errorMessage}`);
1639
1649
  }
1640
1650
  }
1641
1651
  }