capacitor-auth-manager 2.3.0 → 2.4.0

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.
Files changed (38) hide show
  1. package/dist/angular.cjs.js +60 -28
  2. package/dist/angular.cjs.js.map +1 -1
  3. package/dist/core.cjs.js +60 -28
  4. package/dist/core.cjs.js.map +1 -1
  5. package/dist/esm/angular/auth.module.d.ts +2 -1
  6. package/dist/esm/angular/auth.module.js.map +1 -1
  7. package/dist/esm/angular/auth.service.d.ts +5 -5
  8. package/dist/esm/angular/auth.service.js.map +1 -1
  9. package/dist/esm/core/auth-manager.js +2 -0
  10. package/dist/esm/core/auth-manager.js.map +1 -1
  11. package/dist/esm/core/provider-registry.d.ts +2 -2
  12. package/dist/esm/core/provider-registry.js +8 -4
  13. package/dist/esm/core/provider-registry.js.map +1 -1
  14. package/dist/esm/providers/base-provider.js.map +1 -1
  15. package/dist/esm/providers/web/biometric-provider.d.ts +2 -2
  16. package/dist/esm/providers/web/biometric-provider.js +14 -8
  17. package/dist/esm/providers/web/biometric-provider.js.map +1 -1
  18. package/dist/esm/providers/web/email-password-provider.js +7 -6
  19. package/dist/esm/providers/web/email-password-provider.js.map +1 -1
  20. package/dist/esm/providers/web/phone-password-provider.js +8 -6
  21. package/dist/esm/providers/web/phone-password-provider.js.map +1 -1
  22. package/dist/esm/providers/web/username-password-provider.js +5 -4
  23. package/dist/esm/providers/web/username-password-provider.js.map +1 -1
  24. package/dist/esm/utils/error-message.d.ts +8 -0
  25. package/dist/esm/utils/error-message.js +21 -0
  26. package/dist/esm/utils/error-message.js.map +1 -0
  27. package/dist/esm/utils/storage.d.ts +11 -6
  28. package/dist/esm/utils/storage.js +3 -1
  29. package/dist/esm/utils/storage.js.map +1 -1
  30. package/dist/plugin.cjs.js +63 -29
  31. package/dist/plugin.cjs.js.map +1 -1
  32. package/dist/plugin.js +63 -29
  33. package/dist/plugin.js.map +1 -1
  34. package/dist/react.cjs.js +60 -28
  35. package/dist/react.cjs.js.map +1 -1
  36. package/dist/vue.cjs.js +60 -28
  37. package/dist/vue.cjs.js.map +1 -1
  38. package/package.json +1 -1
@@ -626,6 +626,27 @@ class PlatformDetector {
626
626
  }
627
627
  PlatformDetector.platformInfo = null;
628
628
 
629
+ /**
630
+ * Safely extract a human-readable message from an unknown thrown value.
631
+ *
632
+ * `catch` clauses receive `unknown` (the honest type — anything can be thrown), so reach for this
633
+ * instead of typing the binding as `any`. Returns `undefined` when no message can be derived, so
634
+ * callers can fall back to their own default text: `getErrorMessage(error) || 'Default message'`.
635
+ */
636
+ function getErrorMessage(error) {
637
+ if (error instanceof Error) {
638
+ return error.message;
639
+ }
640
+ if (typeof error === 'object' && error !== null && 'message' in error) {
641
+ const message = error.message;
642
+ return typeof message === 'string' ? message : undefined;
643
+ }
644
+ if (typeof error === 'string') {
645
+ return error;
646
+ }
647
+ return undefined;
648
+ }
649
+
629
650
  /**
630
651
  * Built-in provider manifests (display metadata + human-readable setup instructions).
631
652
  *
@@ -1113,7 +1134,7 @@ class ProviderRegistry {
1113
1134
  return (_b = this.NAME_ALIASES[name]) !== null && _b !== void 0 ? _b : name;
1114
1135
  }
1115
1136
  static async getProvider(name, options, deps) {
1116
- var _b, _c, _d, _e;
1137
+ var _b, _c;
1117
1138
  const key = this.canonicalName(name);
1118
1139
  // Check if already loaded
1119
1140
  const existing = this.providers.get(key);
@@ -1138,7 +1159,9 @@ class ProviderRegistry {
1138
1159
  }
1139
1160
  }
1140
1161
  try {
1141
- // Load the provider class
1162
+ // Load the provider class. Every loader resolves to `{ default: <ProviderConstructor> }`
1163
+ // (see registerLoader calls above); narrow `default` to that constructor shape so the
1164
+ // `new ProviderClass(...)` below type-checks without resorting to `any`.
1142
1165
  const module = await loader();
1143
1166
  const ProviderClass = module.default;
1144
1167
  // Build the constructor argument. BaseAuthProvider subclasses need a full
@@ -1171,8 +1194,9 @@ class ProviderRegistry {
1171
1194
  }
1172
1195
  catch (error) {
1173
1196
  // Check if it's a missing dependency error
1174
- if (((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot find module')) ||
1175
- ((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to resolve module'))) {
1197
+ const message = getErrorMessage(error);
1198
+ if ((message === null || message === void 0 ? void 0 : message.includes('Cannot find module')) ||
1199
+ (message === null || message === void 0 ? void 0 : message.includes('Failed to resolve module'))) {
1176
1200
  const manifest = this.manifests.get(this.canonicalName(name));
1177
1201
  if (manifest === null || manifest === void 0 ? void 0 : manifest.packageName) {
1178
1202
  throw new Error(`Missing dependency for ${manifest.displayName} provider.\n\n` +
@@ -1425,6 +1449,8 @@ class AuthManagerCore {
1425
1449
  // email/password/phoneNumber/username) AND kept nested under `credentials` for
1426
1450
  // providers that read them there.
1427
1451
  this.logger.info(`Signing in with ${providerName}`);
1452
+ // The provider reads credentials/options from this merged shape; `provider` is supplied via
1453
+ // construction, not here, so we assert to SignInOptions (whose `provider` is required).
1428
1454
  const result = await provider.signIn(Object.assign(Object.assign(Object.assign({}, signInOptions.options), ((_b = signInOptions.credentials) !== null && _b !== void 0 ? _b : {})), { credentials: signInOptions.credentials }));
1429
1455
  // Update state
1430
1456
  this.updateState({
@@ -5170,7 +5196,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
5170
5196
  catch (error) {
5171
5197
  if (error instanceof AuthError)
5172
5198
  throw error;
5173
- throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Failed to sign in with email and password');
5199
+ throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with email and password');
5174
5200
  }
5175
5201
  }
5176
5202
  async signUp(options) {
@@ -5255,7 +5281,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
5255
5281
  catch (error) {
5256
5282
  if (error instanceof AuthError)
5257
5283
  throw error;
5258
- throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error.message || 'Failed to create account');
5284
+ throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
5259
5285
  }
5260
5286
  }
5261
5287
  async signOut() {
@@ -5321,7 +5347,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
5321
5347
  catch (error) {
5322
5348
  if (error instanceof AuthError)
5323
5349
  throw error;
5324
- throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Failed to refresh token');
5350
+ throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
5325
5351
  }
5326
5352
  }
5327
5353
  async updatePassword(currentPassword, newPassword) {
@@ -5357,7 +5383,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
5357
5383
  catch (error) {
5358
5384
  if (error instanceof AuthError)
5359
5385
  throw error;
5360
- throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to update password');
5386
+ throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
5361
5387
  }
5362
5388
  }
5363
5389
  async sendPasswordResetEmail(email) {
@@ -5383,7 +5409,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
5383
5409
  catch (error) {
5384
5410
  if (error instanceof AuthError)
5385
5411
  throw error;
5386
- throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset email');
5412
+ throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to send password reset email');
5387
5413
  }
5388
5414
  }
5389
5415
  async sendEmailVerification() {
@@ -5412,7 +5438,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
5412
5438
  catch (error) {
5413
5439
  if (error instanceof AuthError)
5414
5440
  throw error;
5415
- throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error.message || 'Failed to send verification email');
5441
+ throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Failed to send verification email');
5416
5442
  }
5417
5443
  }
5418
5444
  isValidEmail(email) {
@@ -5476,7 +5502,9 @@ class BiometricProvider extends BaseAuthProvider {
5476
5502
  async loadBiometricPlugin() {
5477
5503
  try {
5478
5504
  // Dynamic import to avoid errors if plugin not installed
5479
- const { BiometricAuth } = await import('capacitor-biometric-authentication');
5505
+ const { BiometricAuth } = await import(
5506
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- optional peer dep; module may be absent at build time
5507
+ 'capacitor-biometric-authentication');
5480
5508
  this.biometricAuth = BiometricAuth;
5481
5509
  }
5482
5510
  catch (_a) {
@@ -5484,7 +5512,6 @@ class BiometricProvider extends BaseAuthProvider {
5484
5512
  }
5485
5513
  }
5486
5514
  async signIn(_options) {
5487
- var _a, _b, _c;
5488
5515
  if (!this.biometricAuth) {
5489
5516
  throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, 'Biometric authentication plugin is not installed. Please install capacitor-biometric-authentication');
5490
5517
  }
@@ -5539,18 +5566,22 @@ class BiometricProvider extends BaseAuthProvider {
5539
5566
  if (error instanceof AuthError)
5540
5567
  throw error;
5541
5568
  // Handle biometric errors
5542
- if (error.code === 'userCancel' || ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('cancel'))) {
5569
+ const errorCode = typeof error === 'object' && error !== null && 'code' in error
5570
+ ? error.code
5571
+ : undefined;
5572
+ const errorMessage = getErrorMessage(error);
5573
+ if (errorCode === 'userCancel' || (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('cancel'))) {
5543
5574
  throw new AuthError(AuthErrorCode.USER_CANCELLED, 'Authentication cancelled by user');
5544
5575
  }
5545
- else if (error.code === 'biometryLockout' ||
5546
- ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('lockout'))) {
5576
+ else if (errorCode === 'biometryLockout' ||
5577
+ (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('lockout'))) {
5547
5578
  throw new AuthError(AuthErrorCode.BIOMETRIC_LOCKOUT, 'Too many failed attempts. Biometry is locked.');
5548
5579
  }
5549
- else if (error.code === 'biometryNotEnrolled' ||
5550
- ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('enrolled'))) {
5580
+ else if (errorCode === 'biometryNotEnrolled' ||
5581
+ (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('enrolled'))) {
5551
5582
  throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_ENROLLED, 'No biometric credentials are enrolled');
5552
5583
  }
5553
- throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, error.message || 'Biometric authentication failed');
5584
+ throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, errorMessage || 'Biometric authentication failed');
5554
5585
  }
5555
5586
  }
5556
5587
  async signOut() {
@@ -6109,7 +6140,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
6109
6140
  catch (error) {
6110
6141
  if (error instanceof AuthError)
6111
6142
  throw error;
6112
- throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Failed to sign in with username and password');
6143
+ throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with username and password');
6113
6144
  }
6114
6145
  }
6115
6146
  async signUp(options) {
@@ -6201,7 +6232,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
6201
6232
  catch (error) {
6202
6233
  if (error instanceof AuthError)
6203
6234
  throw error;
6204
- throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error.message || 'Failed to create account');
6235
+ throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
6205
6236
  }
6206
6237
  }
6207
6238
  async signOut() {
@@ -6267,7 +6298,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
6267
6298
  catch (error) {
6268
6299
  if (error instanceof AuthError)
6269
6300
  throw error;
6270
- throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Failed to refresh token');
6301
+ throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
6271
6302
  }
6272
6303
  }
6273
6304
  async updatePassword(currentPassword, newPassword) {
@@ -6303,7 +6334,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
6303
6334
  catch (error) {
6304
6335
  if (error instanceof AuthError)
6305
6336
  throw error;
6306
- throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to update password');
6337
+ throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
6307
6338
  }
6308
6339
  }
6309
6340
  async checkUsernameAvailability(username) {
@@ -6710,7 +6741,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
6710
6741
  catch (error) {
6711
6742
  if (error instanceof AuthError)
6712
6743
  throw error;
6713
- throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
6744
+ throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Sign in failed');
6714
6745
  }
6715
6746
  }
6716
6747
  async signUp(phoneNumber, password) {
@@ -6774,7 +6805,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
6774
6805
  catch (error) {
6775
6806
  if (error instanceof AuthError)
6776
6807
  throw error;
6777
- throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error.message || 'Sign up failed');
6808
+ throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Sign up failed');
6778
6809
  }
6779
6810
  }
6780
6811
  async sendVerificationCode(phoneNumber) {
@@ -6842,7 +6873,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
6842
6873
  catch (error) {
6843
6874
  if (error instanceof AuthError)
6844
6875
  throw error;
6845
- throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error.message || 'Phone verification failed');
6876
+ throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Phone verification failed');
6846
6877
  }
6847
6878
  }
6848
6879
  async signOut() {
@@ -6898,7 +6929,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
6898
6929
  catch (error) {
6899
6930
  if (error instanceof AuthError)
6900
6931
  throw error;
6901
- throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Token refresh failed');
6932
+ throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Token refresh failed');
6902
6933
  }
6903
6934
  }
6904
6935
  async initialize() {
@@ -6937,6 +6968,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
6937
6968
  // Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
6938
6969
  // which has a different signature (this builds a phone-specific result from a backend payload).
6939
6970
  buildAuthResult(data, phoneNumber, isNewUser = false) {
6971
+ var _a, _b;
6940
6972
  const user = {
6941
6973
  uid: data.uid || this.generateUid(phoneNumber),
6942
6974
  email: data.email || null,
@@ -6960,8 +6992,8 @@ class PhonePasswordProvider extends BaseAuthProvider {
6960
6992
  },
6961
6993
  };
6962
6994
  this.currentUser = user;
6963
- this.storedAccessToken = data.accessToken;
6964
- this.storedRefreshToken = data.refreshToken;
6995
+ this.storedAccessToken = (_a = data.accessToken) !== null && _a !== void 0 ? _a : null;
6996
+ this.storedRefreshToken = (_b = data.refreshToken) !== null && _b !== void 0 ? _b : null;
6965
6997
  return {
6966
6998
  user,
6967
6999
  credential: {