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
package/dist/core.cjs.js CHANGED
@@ -620,6 +620,27 @@ class PlatformDetector {
620
620
  }
621
621
  PlatformDetector.platformInfo = null;
622
622
 
623
+ /**
624
+ * Safely extract a human-readable message from an unknown thrown value.
625
+ *
626
+ * `catch` clauses receive `unknown` (the honest type — anything can be thrown), so reach for this
627
+ * instead of typing the binding as `any`. Returns `undefined` when no message can be derived, so
628
+ * callers can fall back to their own default text: `getErrorMessage(error) || 'Default message'`.
629
+ */
630
+ function getErrorMessage(error) {
631
+ if (error instanceof Error) {
632
+ return error.message;
633
+ }
634
+ if (typeof error === 'object' && error !== null && 'message' in error) {
635
+ const message = error.message;
636
+ return typeof message === 'string' ? message : undefined;
637
+ }
638
+ if (typeof error === 'string') {
639
+ return error;
640
+ }
641
+ return undefined;
642
+ }
643
+
623
644
  /**
624
645
  * Built-in provider manifests (display metadata + human-readable setup instructions).
625
646
  *
@@ -1107,7 +1128,7 @@ class ProviderRegistry {
1107
1128
  return (_b = this.NAME_ALIASES[name]) !== null && _b !== void 0 ? _b : name;
1108
1129
  }
1109
1130
  static async getProvider(name, options, deps) {
1110
- var _b, _c, _d, _e;
1131
+ var _b, _c;
1111
1132
  const key = this.canonicalName(name);
1112
1133
  // Check if already loaded
1113
1134
  const existing = this.providers.get(key);
@@ -1132,7 +1153,9 @@ class ProviderRegistry {
1132
1153
  }
1133
1154
  }
1134
1155
  try {
1135
- // Load the provider class
1156
+ // Load the provider class. Every loader resolves to `{ default: <ProviderConstructor> }`
1157
+ // (see registerLoader calls above); narrow `default` to that constructor shape so the
1158
+ // `new ProviderClass(...)` below type-checks without resorting to `any`.
1136
1159
  const module = await loader();
1137
1160
  const ProviderClass = module.default;
1138
1161
  // Build the constructor argument. BaseAuthProvider subclasses need a full
@@ -1165,8 +1188,9 @@ class ProviderRegistry {
1165
1188
  }
1166
1189
  catch (error) {
1167
1190
  // Check if it's a missing dependency error
1168
- if (((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot find module')) ||
1169
- ((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to resolve module'))) {
1191
+ const message = getErrorMessage(error);
1192
+ if ((message === null || message === void 0 ? void 0 : message.includes('Cannot find module')) ||
1193
+ (message === null || message === void 0 ? void 0 : message.includes('Failed to resolve module'))) {
1170
1194
  const manifest = this.manifests.get(this.canonicalName(name));
1171
1195
  if (manifest === null || manifest === void 0 ? void 0 : manifest.packageName) {
1172
1196
  throw new Error(`Missing dependency for ${manifest.displayName} provider.\n\n` +
@@ -1419,6 +1443,8 @@ class AuthManagerCore {
1419
1443
  // email/password/phoneNumber/username) AND kept nested under `credentials` for
1420
1444
  // providers that read them there.
1421
1445
  this.logger.info(`Signing in with ${providerName}`);
1446
+ // The provider reads credentials/options from this merged shape; `provider` is supplied via
1447
+ // construction, not here, so we assert to SignInOptions (whose `provider` is required).
1422
1448
  const result = await provider.signIn(Object.assign(Object.assign(Object.assign({}, signInOptions.options), ((_b = signInOptions.credentials) !== null && _b !== void 0 ? _b : {})), { credentials: signInOptions.credentials }));
1423
1449
  // Update state
1424
1450
  this.updateState({
@@ -4820,7 +4846,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
4820
4846
  catch (error) {
4821
4847
  if (error instanceof AuthError)
4822
4848
  throw error;
4823
- throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Failed to sign in with email and password');
4849
+ throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with email and password');
4824
4850
  }
4825
4851
  }
4826
4852
  async signUp(options) {
@@ -4905,7 +4931,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
4905
4931
  catch (error) {
4906
4932
  if (error instanceof AuthError)
4907
4933
  throw error;
4908
- throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error.message || 'Failed to create account');
4934
+ throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
4909
4935
  }
4910
4936
  }
4911
4937
  async signOut() {
@@ -4971,7 +4997,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
4971
4997
  catch (error) {
4972
4998
  if (error instanceof AuthError)
4973
4999
  throw error;
4974
- throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Failed to refresh token');
5000
+ throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
4975
5001
  }
4976
5002
  }
4977
5003
  async updatePassword(currentPassword, newPassword) {
@@ -5007,7 +5033,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
5007
5033
  catch (error) {
5008
5034
  if (error instanceof AuthError)
5009
5035
  throw error;
5010
- throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to update password');
5036
+ throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
5011
5037
  }
5012
5038
  }
5013
5039
  async sendPasswordResetEmail(email) {
@@ -5033,7 +5059,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
5033
5059
  catch (error) {
5034
5060
  if (error instanceof AuthError)
5035
5061
  throw error;
5036
- throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset email');
5062
+ throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to send password reset email');
5037
5063
  }
5038
5064
  }
5039
5065
  async sendEmailVerification() {
@@ -5062,7 +5088,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
5062
5088
  catch (error) {
5063
5089
  if (error instanceof AuthError)
5064
5090
  throw error;
5065
- throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error.message || 'Failed to send verification email');
5091
+ throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Failed to send verification email');
5066
5092
  }
5067
5093
  }
5068
5094
  isValidEmail(email) {
@@ -5126,7 +5152,9 @@ class BiometricProvider extends BaseAuthProvider {
5126
5152
  async loadBiometricPlugin() {
5127
5153
  try {
5128
5154
  // Dynamic import to avoid errors if plugin not installed
5129
- const { BiometricAuth } = await import('capacitor-biometric-authentication');
5155
+ const { BiometricAuth } = await import(
5156
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- optional peer dep; module may be absent at build time
5157
+ 'capacitor-biometric-authentication');
5130
5158
  this.biometricAuth = BiometricAuth;
5131
5159
  }
5132
5160
  catch (_a) {
@@ -5134,7 +5162,6 @@ class BiometricProvider extends BaseAuthProvider {
5134
5162
  }
5135
5163
  }
5136
5164
  async signIn(_options) {
5137
- var _a, _b, _c;
5138
5165
  if (!this.biometricAuth) {
5139
5166
  throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, 'Biometric authentication plugin is not installed. Please install capacitor-biometric-authentication');
5140
5167
  }
@@ -5189,18 +5216,22 @@ class BiometricProvider extends BaseAuthProvider {
5189
5216
  if (error instanceof AuthError)
5190
5217
  throw error;
5191
5218
  // Handle biometric errors
5192
- if (error.code === 'userCancel' || ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('cancel'))) {
5219
+ const errorCode = typeof error === 'object' && error !== null && 'code' in error
5220
+ ? error.code
5221
+ : undefined;
5222
+ const errorMessage = getErrorMessage(error);
5223
+ if (errorCode === 'userCancel' || (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('cancel'))) {
5193
5224
  throw new AuthError(AuthErrorCode.USER_CANCELLED, 'Authentication cancelled by user');
5194
5225
  }
5195
- else if (error.code === 'biometryLockout' ||
5196
- ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('lockout'))) {
5226
+ else if (errorCode === 'biometryLockout' ||
5227
+ (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('lockout'))) {
5197
5228
  throw new AuthError(AuthErrorCode.BIOMETRIC_LOCKOUT, 'Too many failed attempts. Biometry is locked.');
5198
5229
  }
5199
- else if (error.code === 'biometryNotEnrolled' ||
5200
- ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('enrolled'))) {
5230
+ else if (errorCode === 'biometryNotEnrolled' ||
5231
+ (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('enrolled'))) {
5201
5232
  throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_ENROLLED, 'No biometric credentials are enrolled');
5202
5233
  }
5203
- throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, error.message || 'Biometric authentication failed');
5234
+ throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, errorMessage || 'Biometric authentication failed');
5204
5235
  }
5205
5236
  }
5206
5237
  async signOut() {
@@ -5759,7 +5790,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
5759
5790
  catch (error) {
5760
5791
  if (error instanceof AuthError)
5761
5792
  throw error;
5762
- throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Failed to sign in with username and password');
5793
+ throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with username and password');
5763
5794
  }
5764
5795
  }
5765
5796
  async signUp(options) {
@@ -5851,7 +5882,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
5851
5882
  catch (error) {
5852
5883
  if (error instanceof AuthError)
5853
5884
  throw error;
5854
- throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error.message || 'Failed to create account');
5885
+ throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
5855
5886
  }
5856
5887
  }
5857
5888
  async signOut() {
@@ -5917,7 +5948,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
5917
5948
  catch (error) {
5918
5949
  if (error instanceof AuthError)
5919
5950
  throw error;
5920
- throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Failed to refresh token');
5951
+ throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
5921
5952
  }
5922
5953
  }
5923
5954
  async updatePassword(currentPassword, newPassword) {
@@ -5953,7 +5984,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
5953
5984
  catch (error) {
5954
5985
  if (error instanceof AuthError)
5955
5986
  throw error;
5956
- throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to update password');
5987
+ throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
5957
5988
  }
5958
5989
  }
5959
5990
  async checkUsernameAvailability(username) {
@@ -6360,7 +6391,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
6360
6391
  catch (error) {
6361
6392
  if (error instanceof AuthError)
6362
6393
  throw error;
6363
- throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
6394
+ throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Sign in failed');
6364
6395
  }
6365
6396
  }
6366
6397
  async signUp(phoneNumber, password) {
@@ -6424,7 +6455,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
6424
6455
  catch (error) {
6425
6456
  if (error instanceof AuthError)
6426
6457
  throw error;
6427
- throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error.message || 'Sign up failed');
6458
+ throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Sign up failed');
6428
6459
  }
6429
6460
  }
6430
6461
  async sendVerificationCode(phoneNumber) {
@@ -6492,7 +6523,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
6492
6523
  catch (error) {
6493
6524
  if (error instanceof AuthError)
6494
6525
  throw error;
6495
- throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error.message || 'Phone verification failed');
6526
+ throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Phone verification failed');
6496
6527
  }
6497
6528
  }
6498
6529
  async signOut() {
@@ -6548,7 +6579,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
6548
6579
  catch (error) {
6549
6580
  if (error instanceof AuthError)
6550
6581
  throw error;
6551
- throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Token refresh failed');
6582
+ throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Token refresh failed');
6552
6583
  }
6553
6584
  }
6554
6585
  async initialize() {
@@ -6587,6 +6618,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
6587
6618
  // Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
6588
6619
  // which has a different signature (this builds a phone-specific result from a backend payload).
6589
6620
  buildAuthResult(data, phoneNumber, isNewUser = false) {
6621
+ var _a, _b;
6590
6622
  const user = {
6591
6623
  uid: data.uid || this.generateUid(phoneNumber),
6592
6624
  email: data.email || null,
@@ -6610,8 +6642,8 @@ class PhonePasswordProvider extends BaseAuthProvider {
6610
6642
  },
6611
6643
  };
6612
6644
  this.currentUser = user;
6613
- this.storedAccessToken = data.accessToken;
6614
- this.storedRefreshToken = data.refreshToken;
6645
+ this.storedAccessToken = (_a = data.accessToken) !== null && _a !== void 0 ? _a : null;
6646
+ this.storedRefreshToken = (_b = data.refreshToken) !== null && _b !== void 0 ? _b : null;
6615
6647
  return {
6616
6648
  user,
6617
6649
  credential: {