capacitor-auth-manager 2.2.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 (52) hide show
  1. package/dist/angular.cjs.js +159 -108
  2. package/dist/angular.cjs.js.map +1 -1
  3. package/dist/core.cjs.js +159 -108
  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.d.ts +11 -0
  15. package/dist/esm/providers/base-provider.js +30 -3
  16. package/dist/esm/providers/base-provider.js.map +1 -1
  17. package/dist/esm/providers/web/biometric-provider.d.ts +7 -8
  18. package/dist/esm/providers/web/biometric-provider.js +24 -15
  19. package/dist/esm/providers/web/biometric-provider.js.map +1 -1
  20. package/dist/esm/providers/web/email-code-provider.d.ts +5 -7
  21. package/dist/esm/providers/web/email-code-provider.js +10 -11
  22. package/dist/esm/providers/web/email-code-provider.js.map +1 -1
  23. package/dist/esm/providers/web/email-password-provider.d.ts +4 -7
  24. package/dist/esm/providers/web/email-password-provider.js +19 -19
  25. package/dist/esm/providers/web/email-password-provider.js.map +1 -1
  26. package/dist/esm/providers/web/magic-link-provider.d.ts +5 -7
  27. package/dist/esm/providers/web/magic-link-provider.js +12 -13
  28. package/dist/esm/providers/web/magic-link-provider.js.map +1 -1
  29. package/dist/esm/providers/web/phone-password-provider.d.ts +5 -8
  30. package/dist/esm/providers/web/phone-password-provider.js +26 -22
  31. package/dist/esm/providers/web/phone-password-provider.js.map +1 -1
  32. package/dist/esm/providers/web/sms-provider.d.ts +5 -7
  33. package/dist/esm/providers/web/sms-provider.js +11 -13
  34. package/dist/esm/providers/web/sms-provider.js.map +1 -1
  35. package/dist/esm/providers/web/username-password-provider.d.ts +4 -7
  36. package/dist/esm/providers/web/username-password-provider.js +17 -15
  37. package/dist/esm/providers/web/username-password-provider.js.map +1 -1
  38. package/dist/esm/utils/error-message.d.ts +8 -0
  39. package/dist/esm/utils/error-message.js +21 -0
  40. package/dist/esm/utils/error-message.js.map +1 -0
  41. package/dist/esm/utils/storage.d.ts +11 -6
  42. package/dist/esm/utils/storage.js +3 -1
  43. package/dist/esm/utils/storage.js.map +1 -1
  44. package/dist/plugin.cjs.js +162 -109
  45. package/dist/plugin.cjs.js.map +1 -1
  46. package/dist/plugin.js +162 -109
  47. package/dist/plugin.js.map +1 -1
  48. package/dist/react.cjs.js +159 -108
  49. package/dist/react.cjs.js.map +1 -1
  50. package/dist/vue.cjs.js +159 -108
  51. package/dist/vue.cjs.js.map +1 -1
  52. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -433,7 +433,9 @@ var CapacitorAuthManager = (function (exports, core) {
433
433
  }
434
434
  getPrefs() {
435
435
  if (!this.prefsPromise) {
436
- this.prefsPromise = import('@capacitor/preferences').then((m) => m.Preferences);
436
+ this.prefsPromise = import(
437
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- optional peer dep; the module may be absent at build time
438
+ '@capacitor/preferences').then((m) => m.Preferences);
437
439
  }
438
440
  return this.prefsPromise;
439
441
  }
@@ -679,6 +681,27 @@ var CapacitorAuthManager = (function (exports, core) {
679
681
  }
680
682
  PlatformDetector.platformInfo = null;
681
683
 
684
+ /**
685
+ * Safely extract a human-readable message from an unknown thrown value.
686
+ *
687
+ * `catch` clauses receive `unknown` (the honest type — anything can be thrown), so reach for this
688
+ * instead of typing the binding as `any`. Returns `undefined` when no message can be derived, so
689
+ * callers can fall back to their own default text: `getErrorMessage(error) || 'Default message'`.
690
+ */
691
+ function getErrorMessage(error) {
692
+ if (error instanceof Error) {
693
+ return error.message;
694
+ }
695
+ if (typeof error === 'object' && error !== null && 'message' in error) {
696
+ const message = error.message;
697
+ return typeof message === 'string' ? message : undefined;
698
+ }
699
+ if (typeof error === 'string') {
700
+ return error;
701
+ }
702
+ return undefined;
703
+ }
704
+
682
705
  /**
683
706
  * Built-in provider manifests (display metadata + human-readable setup instructions).
684
707
  *
@@ -1166,7 +1189,7 @@ Note: This provider requires a backend service to handle authentication.
1166
1189
  return (_b = this.NAME_ALIASES[name]) !== null && _b !== void 0 ? _b : name;
1167
1190
  }
1168
1191
  static async getProvider(name, options, deps) {
1169
- var _b, _c, _d, _e;
1192
+ var _b, _c;
1170
1193
  const key = this.canonicalName(name);
1171
1194
  // Check if already loaded
1172
1195
  const existing = this.providers.get(key);
@@ -1191,7 +1214,9 @@ Note: This provider requires a backend service to handle authentication.
1191
1214
  }
1192
1215
  }
1193
1216
  try {
1194
- // Load the provider class
1217
+ // Load the provider class. Every loader resolves to `{ default: <ProviderConstructor> }`
1218
+ // (see registerLoader calls above); narrow `default` to that constructor shape so the
1219
+ // `new ProviderClass(...)` below type-checks without resorting to `any`.
1195
1220
  const module = await loader();
1196
1221
  const ProviderClass = module.default;
1197
1222
  // Build the constructor argument. BaseAuthProvider subclasses need a full
@@ -1224,8 +1249,9 @@ Note: This provider requires a backend service to handle authentication.
1224
1249
  }
1225
1250
  catch (error) {
1226
1251
  // Check if it's a missing dependency error
1227
- if (((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot find module')) ||
1228
- ((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to resolve module'))) {
1252
+ const message = getErrorMessage(error);
1253
+ if ((message === null || message === void 0 ? void 0 : message.includes('Cannot find module')) ||
1254
+ (message === null || message === void 0 ? void 0 : message.includes('Failed to resolve module'))) {
1229
1255
  const manifest = this.manifests.get(this.canonicalName(name));
1230
1256
  if (manifest === null || manifest === void 0 ? void 0 : manifest.packageName) {
1231
1257
  throw new Error(`Missing dependency for ${manifest.displayName} provider.\n\n` +
@@ -1478,6 +1504,8 @@ Note: This provider requires a backend service to handle authentication.
1478
1504
  // email/password/phoneNumber/username) AND kept nested under `credentials` for
1479
1505
  // providers that read them there.
1480
1506
  this.logger.info(`Signing in with ${providerName}`);
1507
+ // The provider reads credentials/options from this merged shape; `provider` is supplied via
1508
+ // construction, not here, so we assert to SignInOptions (whose `provider` is required).
1481
1509
  const result = await provider.signIn(Object.assign(Object.assign(Object.assign({}, signInOptions.options), ((_b = signInOptions.credentials) !== null && _b !== void 0 ? _b : {})), { credentials: signInOptions.credentials }));
1482
1510
  // Update state
1483
1511
  this.updateState({
@@ -1898,6 +1926,31 @@ Note: This provider requires a backend service to handle authentication.
1898
1926
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorAuthManagerWeb()),
1899
1927
  });
1900
1928
 
1929
+ /**
1930
+ * Normalize a provider constructor argument into a full {@link BaseProviderConfig}.
1931
+ *
1932
+ * The standalone providers are public (exported from `capacitor-auth-manager/providers/web`) and
1933
+ * get constructed two ways: the factory/registry pass a full {@link BaseProviderConfig}, while
1934
+ * tests and direct consumers pass the provider's own bare options object. This helper accepts
1935
+ * either — a bare object is wrapped with an in-memory storage (`AuthPersistence.NONE`, so it never
1936
+ * touches `window` and stays safe under SSR / Node test environments) plus the shared
1937
+ * {@link defaultLogger}. Callers that pass a full config keep their injected storage/logger.
1938
+ */
1939
+ function resolveProviderConfig(provider, input) {
1940
+ if (typeof input === 'object' &&
1941
+ input !== null &&
1942
+ 'storage' in input &&
1943
+ 'logger' in input &&
1944
+ 'options' in input) {
1945
+ return input;
1946
+ }
1947
+ return {
1948
+ provider,
1949
+ options: (input !== null && input !== void 0 ? input : {}),
1950
+ storage: new WebStorage(exports.AuthPersistence.NONE),
1951
+ logger: defaultLogger,
1952
+ };
1953
+ }
1901
1954
  class BaseAuthProvider {
1902
1955
  get name() {
1903
1956
  return this.provider;
@@ -1917,13 +1970,13 @@ Note: This provider requires a backend service to handle authentication.
1917
1970
  // across every provider (see AuthProviderInterface, where they are optional). Marking them
1918
1971
  // abstract previously forced every subclass to re-implement them just to throw.
1919
1972
  async linkAccount(_options) {
1920
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account linking`, this.provider);
1973
+ throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Account linking is not supported by provider ${this.provider}`, this.provider);
1921
1974
  }
1922
1975
  async unlinkAccount(_options) {
1923
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account unlinking`, this.provider);
1976
+ throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Account unlinking is not supported by provider ${this.provider}`, this.provider);
1924
1977
  }
1925
1978
  async revokeAccess(_token) {
1926
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support access revocation`, this.provider);
1979
+ throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Access revocation is not supported by provider ${this.provider}`, this.provider);
1927
1980
  }
1928
1981
  async getCurrentUser() {
1929
1982
  if (!this.isInitialized) {
@@ -4238,16 +4291,19 @@ Note: This provider requires a backend service to handle authentication.
4238
4291
  }
4239
4292
  }
4240
4293
 
4241
- class MagicLinkProvider {
4242
- constructor(config) {
4243
- this.name = 'magic-link';
4294
+ class MagicLinkProvider extends BaseAuthProvider {
4295
+ get name() {
4296
+ return 'magic-link';
4297
+ }
4298
+ constructor(input) {
4299
+ super(resolveProviderConfig(exports.AuthProvider.EMAIL_MAGIC_LINK, input));
4244
4300
  // Persisted (SSR-guarded localStorage) so a magic link clicked from an email — which opens a
4245
4301
  // FRESH page load with empty in-memory state — can still find its pending entry to verify
4246
4302
  // against. Keyed by the link token (already present in the callback URL); we store only the
4247
4303
  // email + expiry, never any additional secret (see PendingVerificationStore + F-11).
4248
4304
  this.pendingVerification = new PendingVerificationStore('magic-link');
4249
- // Initialize with config
4250
- this.config = config;
4305
+ // Magic link uses its config as-is (no defaults to merge).
4306
+ this.config = this.options;
4251
4307
  // Check for magic link callback on initialization
4252
4308
  this.checkForMagicLinkCallback();
4253
4309
  }
@@ -4497,14 +4553,9 @@ Note: This provider requires a backend service to handle authentication.
4497
4553
  // Magic link auth is supported if we have the required config
4498
4554
  return !!this.config.sendLinkUrl;
4499
4555
  }
4500
- async linkAccount(_options) {
4501
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for magic link authentication');
4502
- }
4503
- async unlinkAccount(_options) {
4504
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for magic link authentication');
4505
- }
4556
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
4506
4557
  async revokeAccess(_token) {
4507
- // Magic link doesn't have persistent access to revoke
4558
+ // Magic link doesn't have persistent access to revoke; clear any pending verification.
4508
4559
  this.pendingVerification.clear();
4509
4560
  }
4510
4561
  }
@@ -4514,16 +4565,18 @@ Note: This provider requires a backend service to handle authentication.
4514
4565
  MagicLinkProvider: MagicLinkProvider
4515
4566
  });
4516
4567
 
4517
- class SMSProvider {
4518
- constructor(config) {
4519
- this.name = 'sms';
4568
+ class SMSProvider extends BaseAuthProvider {
4569
+ get name() {
4570
+ return 'sms';
4571
+ }
4572
+ constructor(input) {
4573
+ super(resolveProviderConfig(exports.AuthProvider.SMS, input));
4520
4574
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
4521
4575
  // page change between sending and verifying the code. Only non-secret metadata is stored —
4522
4576
  // never the SMS code itself (see PendingVerificationStore + F-11).
4523
4577
  this.pendingVerifications = new PendingVerificationStore('sms');
4524
4578
  this.MAX_ATTEMPTS = 3;
4525
- // Initialize with config
4526
- this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, config);
4579
+ this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, this.options);
4527
4580
  }
4528
4581
  async signIn(options) {
4529
4582
  if (!(options === null || options === void 0 ? void 0 : options.phoneNumber)) {
@@ -4761,14 +4814,9 @@ Note: This provider requires a backend service to handle authentication.
4761
4814
  // SMS auth is supported if we have the required config
4762
4815
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
4763
4816
  }
4764
- async linkAccount(_options) {
4765
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for SMS authentication');
4766
- }
4767
- async unlinkAccount(_options) {
4768
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for SMS authentication');
4769
- }
4817
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
4770
4818
  async revokeAccess(_token) {
4771
- // SMS auth doesn't have persistent access to revoke
4819
+ // SMS auth doesn't have persistent access to revoke; clear any pending verification.
4772
4820
  this.pendingVerifications.clear();
4773
4821
  }
4774
4822
  }
@@ -4778,20 +4826,23 @@ Note: This provider requires a backend service to handle authentication.
4778
4826
  SMSProvider: SMSProvider
4779
4827
  });
4780
4828
 
4781
- class EmailPasswordProvider {
4782
- constructor(config) {
4783
- this.name = 'email-password';
4784
- this.currentUser = null;
4829
+ class EmailPasswordProvider extends BaseAuthProvider {
4830
+ get name() {
4831
+ return 'email-password';
4832
+ }
4833
+ constructor(input) {
4834
+ super(resolveProviderConfig(exports.AuthProvider.EMAIL_PASSWORD, input));
4835
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
4836
+ // so email/password sessions stay in-memory exactly as before (no new storage persistence).
4785
4837
  this.authToken = null;
4786
4838
  this.refreshTokenValue = null;
4787
- // Initialize with config
4788
4839
  this.config = Object.assign({ allowSignUp: true, passwordRequirements: {
4789
4840
  minLength: 8,
4790
4841
  requireUppercase: true,
4791
4842
  requireLowercase: true,
4792
4843
  requireNumbers: true,
4793
4844
  requireSpecialChars: false,
4794
- } }, config);
4845
+ } }, this.options);
4795
4846
  }
4796
4847
  async signIn(options) {
4797
4848
  if (!(options === null || options === void 0 ? void 0 : options.email) || !(options === null || options === void 0 ? void 0 : options.password)) {
@@ -4861,7 +4912,7 @@ Note: This provider requires a backend service to handle authentication.
4861
4912
  catch (error) {
4862
4913
  if (error instanceof AuthError)
4863
4914
  throw error;
4864
- throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, error.message || 'Failed to sign in with email and password');
4915
+ throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with email and password');
4865
4916
  }
4866
4917
  }
4867
4918
  async signUp(options) {
@@ -4946,7 +4997,7 @@ Note: This provider requires a backend service to handle authentication.
4946
4997
  catch (error) {
4947
4998
  if (error instanceof AuthError)
4948
4999
  throw error;
4949
- throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, error.message || 'Failed to create account');
5000
+ throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
4950
5001
  }
4951
5002
  }
4952
5003
  async signOut() {
@@ -5012,7 +5063,7 @@ Note: This provider requires a backend service to handle authentication.
5012
5063
  catch (error) {
5013
5064
  if (error instanceof AuthError)
5014
5065
  throw error;
5015
- throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Failed to refresh token');
5066
+ throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
5016
5067
  }
5017
5068
  }
5018
5069
  async updatePassword(currentPassword, newPassword) {
@@ -5048,7 +5099,7 @@ Note: This provider requires a backend service to handle authentication.
5048
5099
  catch (error) {
5049
5100
  if (error instanceof AuthError)
5050
5101
  throw error;
5051
- throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, error.message || 'Failed to update password');
5102
+ throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
5052
5103
  }
5053
5104
  }
5054
5105
  async sendPasswordResetEmail(email) {
@@ -5074,7 +5125,7 @@ Note: This provider requires a backend service to handle authentication.
5074
5125
  catch (error) {
5075
5126
  if (error instanceof AuthError)
5076
5127
  throw error;
5077
- throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset email');
5128
+ throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to send password reset email');
5078
5129
  }
5079
5130
  }
5080
5131
  async sendEmailVerification() {
@@ -5103,7 +5154,7 @@ Note: This provider requires a backend service to handle authentication.
5103
5154
  catch (error) {
5104
5155
  if (error instanceof AuthError)
5105
5156
  throw error;
5106
- throw new AuthError(exports.AuthErrorCode.VERIFICATION_FAILED, error.message || 'Failed to send verification email');
5157
+ throw new AuthError(exports.AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Failed to send verification email');
5107
5158
  }
5108
5159
  }
5109
5160
  isValidEmail(email) {
@@ -5137,12 +5188,7 @@ Note: This provider requires a backend service to handle authentication.
5137
5188
  // Email/Password auth is supported if we have the required config
5138
5189
  return !!this.config.apiUrl;
5139
5190
  }
5140
- async linkAccount(_options) {
5141
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email/password authentication');
5142
- }
5143
- async unlinkAccount(_options) {
5144
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email/password authentication');
5145
- }
5191
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
5146
5192
  async revokeAccess(_token) {
5147
5193
  // For email/password auth, revoking access means signing out
5148
5194
  await this.signOut();
@@ -5154,11 +5200,15 @@ Note: This provider requires a backend service to handle authentication.
5154
5200
  EmailPasswordProvider: EmailPasswordProvider
5155
5201
  });
5156
5202
 
5157
- class BiometricProvider {
5158
- constructor(config = {}) {
5159
- this.name = 'biometric';
5203
+ class BiometricProvider extends BaseAuthProvider {
5204
+ get name() {
5205
+ return 'biometric';
5206
+ }
5207
+ constructor(input = {}) {
5208
+ super(resolveProviderConfig(exports.AuthProvider.BIOMETRIC, input));
5160
5209
  this.biometricAuth = null;
5161
5210
  this.cryptoKeyPromise = null;
5211
+ const config = this.options;
5162
5212
  this.config = Object.assign({ reason: 'Authenticate to access your account', title: 'Authentication Required', subtitle: 'Access your account securely', fallbackTitle: 'Use Passcode', requireRecentAuth: true, recentAuthTimeout: 5 * 60 * 1000 }, config);
5163
5213
  this.storageKey =
5164
5214
  config.storageKey || 'capacitor-auth-biometric-credentials';
@@ -5168,7 +5218,9 @@ Note: This provider requires a backend service to handle authentication.
5168
5218
  async loadBiometricPlugin() {
5169
5219
  try {
5170
5220
  // Dynamic import to avoid errors if plugin not installed
5171
- const { BiometricAuth } = await import('capacitor-biometric-authentication');
5221
+ const { BiometricAuth } = await import(
5222
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- optional peer dep; module may be absent at build time
5223
+ 'capacitor-biometric-authentication');
5172
5224
  this.biometricAuth = BiometricAuth;
5173
5225
  }
5174
5226
  catch (_a) {
@@ -5176,7 +5228,6 @@ Note: This provider requires a backend service to handle authentication.
5176
5228
  }
5177
5229
  }
5178
5230
  async signIn(_options) {
5179
- var _a, _b, _c;
5180
5231
  if (!this.biometricAuth) {
5181
5232
  throw new AuthError(exports.AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, 'Biometric authentication plugin is not installed. Please install capacitor-biometric-authentication');
5182
5233
  }
@@ -5231,18 +5282,22 @@ Note: This provider requires a backend service to handle authentication.
5231
5282
  if (error instanceof AuthError)
5232
5283
  throw error;
5233
5284
  // Handle biometric errors
5234
- if (error.code === 'userCancel' || ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('cancel'))) {
5285
+ const errorCode = typeof error === 'object' && error !== null && 'code' in error
5286
+ ? error.code
5287
+ : undefined;
5288
+ const errorMessage = getErrorMessage(error);
5289
+ if (errorCode === 'userCancel' || (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('cancel'))) {
5235
5290
  throw new AuthError(exports.AuthErrorCode.USER_CANCELLED, 'Authentication cancelled by user');
5236
5291
  }
5237
- else if (error.code === 'biometryLockout' ||
5238
- ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('lockout'))) {
5292
+ else if (errorCode === 'biometryLockout' ||
5293
+ (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('lockout'))) {
5239
5294
  throw new AuthError(exports.AuthErrorCode.BIOMETRIC_LOCKOUT, 'Too many failed attempts. Biometry is locked.');
5240
5295
  }
5241
- else if (error.code === 'biometryNotEnrolled' ||
5242
- ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('enrolled'))) {
5296
+ else if (errorCode === 'biometryNotEnrolled' ||
5297
+ (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('enrolled'))) {
5243
5298
  throw new AuthError(exports.AuthErrorCode.BIOMETRIC_NOT_ENROLLED, 'No biometric credentials are enrolled');
5244
5299
  }
5245
- throw new AuthError(exports.AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, error.message || 'Biometric authentication failed');
5300
+ throw new AuthError(exports.AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, errorMessage || 'Biometric authentication failed');
5246
5301
  }
5247
5302
  }
5248
5303
  async signOut() {
@@ -5442,9 +5497,7 @@ Note: This provider requires a backend service to handle authentication.
5442
5497
  const result = await this.isAvailable();
5443
5498
  return result.available;
5444
5499
  }
5445
- async linkAccount(_options) {
5446
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for biometric authentication');
5447
- }
5500
+ // linkAccount inherits BaseAuthProvider's OPERATION_NOT_ALLOWED default (F-44).
5448
5501
  async unlinkAccount(_options) {
5449
5502
  // Unlinking biometric auth means clearing stored credentials
5450
5503
  await this.clearStoredCredentials();
@@ -5721,12 +5774,17 @@ Note: This provider requires a backend service to handle authentication.
5721
5774
  LinkedInProvider: LinkedInProvider
5722
5775
  });
5723
5776
 
5724
- class UsernamePasswordProvider {
5725
- constructor(config) {
5726
- this.name = 'username-password';
5727
- this.currentUser = null;
5777
+ class UsernamePasswordProvider extends BaseAuthProvider {
5778
+ get name() {
5779
+ return 'username-password';
5780
+ }
5781
+ constructor(input) {
5782
+ super(resolveProviderConfig(exports.AuthProvider.USERNAME_PASSWORD, input));
5783
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
5784
+ // so username/password sessions stay in-memory exactly as before (no new storage persistence).
5728
5785
  this.authToken = null;
5729
5786
  this.refreshTokenValue = null;
5787
+ const config = this.options;
5730
5788
  this.config = Object.assign({ allowSignUp: true, usernameRequirements: Object.assign({ minLength: 3, maxLength: 20, allowedCharacters: /^[a-zA-Z0-9_-]+$/, reservedUsernames: ['admin', 'root', 'system', 'user'] }, config.usernameRequirements), passwordRequirements: Object.assign({ minLength: 8, requireUppercase: true, requireLowercase: true, requireNumbers: true, requireSpecialChars: false }, config.passwordRequirements) }, config);
5731
5789
  }
5732
5790
  async signIn(options) {
@@ -5798,7 +5856,7 @@ Note: This provider requires a backend service to handle authentication.
5798
5856
  catch (error) {
5799
5857
  if (error instanceof AuthError)
5800
5858
  throw error;
5801
- throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, error.message || 'Failed to sign in with username and password');
5859
+ throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with username and password');
5802
5860
  }
5803
5861
  }
5804
5862
  async signUp(options) {
@@ -5890,7 +5948,7 @@ Note: This provider requires a backend service to handle authentication.
5890
5948
  catch (error) {
5891
5949
  if (error instanceof AuthError)
5892
5950
  throw error;
5893
- throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, error.message || 'Failed to create account');
5951
+ throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
5894
5952
  }
5895
5953
  }
5896
5954
  async signOut() {
@@ -5956,7 +6014,7 @@ Note: This provider requires a backend service to handle authentication.
5956
6014
  catch (error) {
5957
6015
  if (error instanceof AuthError)
5958
6016
  throw error;
5959
- throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Failed to refresh token');
6017
+ throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
5960
6018
  }
5961
6019
  }
5962
6020
  async updatePassword(currentPassword, newPassword) {
@@ -5992,7 +6050,7 @@ Note: This provider requires a backend service to handle authentication.
5992
6050
  catch (error) {
5993
6051
  if (error instanceof AuthError)
5994
6052
  throw error;
5995
- throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, error.message || 'Failed to update password');
6053
+ throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
5996
6054
  }
5997
6055
  }
5998
6056
  async checkUsernameAvailability(username) {
@@ -6071,12 +6129,7 @@ Note: This provider requires a backend service to handle authentication.
6071
6129
  // Username/Password auth is supported if we have the required config
6072
6130
  return !!this.config.apiUrl;
6073
6131
  }
6074
- async linkAccount(_options) {
6075
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for username/password authentication');
6076
- }
6077
- async unlinkAccount(_options) {
6078
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for username/password authentication');
6079
- }
6132
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6080
6133
  async revokeAccess(_token) {
6081
6134
  // For username/password auth, revoking access means signing out
6082
6135
  await this.signOut();
@@ -6088,15 +6141,18 @@ Note: This provider requires a backend service to handle authentication.
6088
6141
  UsernamePasswordProvider: UsernamePasswordProvider
6089
6142
  });
6090
6143
 
6091
- class EmailCodeProvider {
6092
- constructor(config) {
6093
- this.name = 'email-code';
6144
+ class EmailCodeProvider extends BaseAuthProvider {
6145
+ get name() {
6146
+ return 'email-code';
6147
+ }
6148
+ constructor(input) {
6149
+ super(resolveProviderConfig(exports.AuthProvider.EMAIL_CODE, input));
6094
6150
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
6095
6151
  // page change between sending and verifying the code. Only non-secret metadata is stored —
6096
6152
  // never the verification code itself (see PendingVerificationStore + F-11).
6097
6153
  this.pendingVerifications = new PendingVerificationStore('email-code');
6098
6154
  this.MAX_ATTEMPTS = 3;
6099
- this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, config);
6155
+ this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, this.options);
6100
6156
  }
6101
6157
  async signIn(options) {
6102
6158
  if (!(options === null || options === void 0 ? void 0 : options.email)) {
@@ -6291,12 +6347,7 @@ Note: This provider requires a backend service to handle authentication.
6291
6347
  async isSupported() {
6292
6348
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
6293
6349
  }
6294
- async linkAccount(_options) {
6295
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email code authentication');
6296
- }
6297
- async unlinkAccount(_options) {
6298
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email code authentication');
6299
- }
6350
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6300
6351
  async revokeAccess(_token) {
6301
6352
  this.pendingVerifications.clear();
6302
6353
  }
@@ -6341,11 +6392,15 @@ Note: This provider requires a backend service to handle authentication.
6341
6392
  EmailCodeProvider: EmailCodeProvider
6342
6393
  });
6343
6394
 
6344
- class PhonePasswordProvider {
6345
- constructor(config) {
6346
- this.name = 'phone-password';
6395
+ class PhonePasswordProvider extends BaseAuthProvider {
6396
+ get name() {
6397
+ return 'phone-password';
6398
+ }
6399
+ constructor(input) {
6400
+ super(resolveProviderConfig(exports.AuthProvider.PHONE_PASSWORD, input));
6347
6401
  this.pendingVerifications = new Map();
6348
- this.currentUser = null;
6402
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
6403
+ // so phone/password sessions stay in-memory exactly as before (no new storage persistence).
6349
6404
  this.storedAccessToken = null;
6350
6405
  this.storedRefreshToken = null;
6351
6406
  this.config = Object.assign({ countryCode: '+1', requirePhoneVerification: false, passwordStrength: {
@@ -6354,7 +6409,7 @@ Note: This provider requires a backend service to handle authentication.
6354
6409
  requireLowercase: true,
6355
6410
  requireNumbers: true,
6356
6411
  requireSpecialChars: false,
6357
- } }, config);
6412
+ } }, this.options);
6358
6413
  }
6359
6414
  async signIn(options) {
6360
6415
  const credentials = options === null || options === void 0 ? void 0 : options.credentials;
@@ -6397,12 +6452,12 @@ Note: This provider requires a backend service to handle authentication.
6397
6452
  throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
6398
6453
  }
6399
6454
  const data = await response.json();
6400
- return this.createAuthResult(data, phoneNumber);
6455
+ return this.buildAuthResult(data, phoneNumber);
6401
6456
  }
6402
6457
  catch (error) {
6403
6458
  if (error instanceof AuthError)
6404
6459
  throw error;
6405
- throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
6460
+ throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Sign in failed');
6406
6461
  }
6407
6462
  }
6408
6463
  async signUp(phoneNumber, password) {
@@ -6461,12 +6516,12 @@ Note: This provider requires a backend service to handle authentication.
6461
6516
  },
6462
6517
  };
6463
6518
  }
6464
- return this.createAuthResult(data, phoneNumber, true);
6519
+ return this.buildAuthResult(data, phoneNumber, true);
6465
6520
  }
6466
6521
  catch (error) {
6467
6522
  if (error instanceof AuthError)
6468
6523
  throw error;
6469
- throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, error.message || 'Sign up failed');
6524
+ throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Sign up failed');
6470
6525
  }
6471
6526
  }
6472
6527
  async sendVerificationCode(phoneNumber) {
@@ -6529,12 +6584,12 @@ Note: This provider requires a backend service to handle authentication.
6529
6584
  }
6530
6585
  const data = await response.json();
6531
6586
  this.pendingVerifications.delete(phoneNumber);
6532
- return this.createAuthResult(data, phoneNumber);
6587
+ return this.buildAuthResult(data, phoneNumber);
6533
6588
  }
6534
6589
  catch (error) {
6535
6590
  if (error instanceof AuthError)
6536
6591
  throw error;
6537
- throw new AuthError(exports.AuthErrorCode.VERIFICATION_FAILED, error.message || 'Phone verification failed');
6592
+ throw new AuthError(exports.AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Phone verification failed');
6538
6593
  }
6539
6594
  }
6540
6595
  async signOut() {
@@ -6590,7 +6645,7 @@ Note: This provider requires a backend service to handle authentication.
6590
6645
  catch (error) {
6591
6646
  if (error instanceof AuthError)
6592
6647
  throw error;
6593
- throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Token refresh failed');
6648
+ throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Token refresh failed');
6594
6649
  }
6595
6650
  }
6596
6651
  async initialize() {
@@ -6599,12 +6654,7 @@ Note: This provider requires a backend service to handle authentication.
6599
6654
  async isSupported() {
6600
6655
  return !!(this.config.signInUrl && this.config.signUpUrl);
6601
6656
  }
6602
- async linkAccount(_options) {
6603
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for phone/password authentication');
6604
- }
6605
- async unlinkAccount(_options) {
6606
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for phone/password authentication');
6607
- }
6657
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6608
6658
  async revokeAccess(_token) {
6609
6659
  await this.signOut();
6610
6660
  }
@@ -6631,7 +6681,10 @@ Note: This provider requires a backend service to handle authentication.
6631
6681
  throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset');
6632
6682
  }
6633
6683
  }
6634
- createAuthResult(data, phoneNumber, isNewUser = false) {
6684
+ // Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
6685
+ // which has a different signature (this builds a phone-specific result from a backend payload).
6686
+ buildAuthResult(data, phoneNumber, isNewUser = false) {
6687
+ var _a, _b;
6635
6688
  const user = {
6636
6689
  uid: data.uid || this.generateUid(phoneNumber),
6637
6690
  email: data.email || null,
@@ -6655,8 +6708,8 @@ Note: This provider requires a backend service to handle authentication.
6655
6708
  },
6656
6709
  };
6657
6710
  this.currentUser = user;
6658
- this.storedAccessToken = data.accessToken;
6659
- this.storedRefreshToken = data.refreshToken;
6711
+ this.storedAccessToken = (_a = data.accessToken) !== null && _a !== void 0 ? _a : null;
6712
+ this.storedRefreshToken = (_b = data.refreshToken) !== null && _b !== void 0 ? _b : null;
6660
6713
  return {
6661
6714
  user,
6662
6715
  credential: {