@explorins/pers-signer 1.0.31 → 1.0.33

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
  }
@@ -2147,12 +2157,16 @@ class PersSignerSDK {
2147
2157
  */
2148
2158
  constructor(config) {
2149
2159
  this.config = config;
2160
+ // Safe hostname/origin extraction - window.location may be undefined in React Native
2161
+ const hasWindowLocation = typeof window !== 'undefined' && typeof window.location !== 'undefined';
2162
+ const hostname = hasWindowLocation ? window.location.hostname : 'localhost';
2163
+ const origin = hasWindowLocation ? window.location.origin : undefined;
2150
2164
  setConfigProvider(new WebConfigProvider({
2151
2165
  apiUrl: config.apiUrl || SIGNER_CONFIG.DEFAULT_SIGNER_API_URL,
2152
2166
  relyingParty: {
2153
- id: typeof window !== 'undefined' ? window.location.hostname : 'localhost',
2167
+ id: hostname,
2154
2168
  name: config.relyingPartyName || SIGNER_CONFIG.DEFAULT_RELYING_PARTY_NAME,
2155
- origin: typeof window !== 'undefined' ? window.location.origin : undefined,
2169
+ origin: origin,
2156
2170
  },
2157
2171
  }));
2158
2172
  this.authenticationService = new AuthenticationService(this.config);