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/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({
@@ -1834,6 +1860,31 @@ class AuthManagerCore {
1834
1860
  // Create singleton instance
1835
1861
  const auth = new AuthManagerCore();
1836
1862
 
1863
+ /**
1864
+ * Normalize a provider constructor argument into a full {@link BaseProviderConfig}.
1865
+ *
1866
+ * The standalone providers are public (exported from `capacitor-auth-manager/providers/web`) and
1867
+ * get constructed two ways: the factory/registry pass a full {@link BaseProviderConfig}, while
1868
+ * tests and direct consumers pass the provider's own bare options object. This helper accepts
1869
+ * either — a bare object is wrapped with an in-memory storage (`AuthPersistence.NONE`, so it never
1870
+ * touches `window` and stays safe under SSR / Node test environments) plus the shared
1871
+ * {@link defaultLogger}. Callers that pass a full config keep their injected storage/logger.
1872
+ */
1873
+ function resolveProviderConfig(provider, input) {
1874
+ if (typeof input === 'object' &&
1875
+ input !== null &&
1876
+ 'storage' in input &&
1877
+ 'logger' in input &&
1878
+ 'options' in input) {
1879
+ return input;
1880
+ }
1881
+ return {
1882
+ provider,
1883
+ options: (input !== null && input !== void 0 ? input : {}),
1884
+ storage: new WebStorage(AuthPersistence.NONE),
1885
+ logger: defaultLogger,
1886
+ };
1887
+ }
1837
1888
  class BaseAuthProvider {
1838
1889
  get name() {
1839
1890
  return this.provider;
@@ -1853,13 +1904,13 @@ class BaseAuthProvider {
1853
1904
  // across every provider (see AuthProviderInterface, where they are optional). Marking them
1854
1905
  // abstract previously forced every subclass to re-implement them just to throw.
1855
1906
  async linkAccount(_options) {
1856
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account linking`, this.provider);
1907
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account linking is not supported by provider ${this.provider}`, this.provider);
1857
1908
  }
1858
1909
  async unlinkAccount(_options) {
1859
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account unlinking`, this.provider);
1910
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account unlinking is not supported by provider ${this.provider}`, this.provider);
1860
1911
  }
1861
1912
  async revokeAccess(_token) {
1862
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support access revocation`, this.provider);
1913
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Access revocation is not supported by provider ${this.provider}`, this.provider);
1863
1914
  }
1864
1915
  async getCurrentUser() {
1865
1916
  if (!this.isInitialized) {
@@ -4174,16 +4225,19 @@ class PendingVerificationStore {
4174
4225
  }
4175
4226
  }
4176
4227
 
4177
- class MagicLinkProvider {
4178
- constructor(config) {
4179
- this.name = 'magic-link';
4228
+ class MagicLinkProvider extends BaseAuthProvider {
4229
+ get name() {
4230
+ return 'magic-link';
4231
+ }
4232
+ constructor(input) {
4233
+ super(resolveProviderConfig(AuthProvider.EMAIL_MAGIC_LINK, input));
4180
4234
  // Persisted (SSR-guarded localStorage) so a magic link clicked from an email — which opens a
4181
4235
  // FRESH page load with empty in-memory state — can still find its pending entry to verify
4182
4236
  // against. Keyed by the link token (already present in the callback URL); we store only the
4183
4237
  // email + expiry, never any additional secret (see PendingVerificationStore + F-11).
4184
4238
  this.pendingVerification = new PendingVerificationStore('magic-link');
4185
- // Initialize with config
4186
- this.config = config;
4239
+ // Magic link uses its config as-is (no defaults to merge).
4240
+ this.config = this.options;
4187
4241
  // Check for magic link callback on initialization
4188
4242
  this.checkForMagicLinkCallback();
4189
4243
  }
@@ -4433,14 +4487,9 @@ class MagicLinkProvider {
4433
4487
  // Magic link auth is supported if we have the required config
4434
4488
  return !!this.config.sendLinkUrl;
4435
4489
  }
4436
- async linkAccount(_options) {
4437
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for magic link authentication');
4438
- }
4439
- async unlinkAccount(_options) {
4440
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for magic link authentication');
4441
- }
4490
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
4442
4491
  async revokeAccess(_token) {
4443
- // Magic link doesn't have persistent access to revoke
4492
+ // Magic link doesn't have persistent access to revoke; clear any pending verification.
4444
4493
  this.pendingVerification.clear();
4445
4494
  }
4446
4495
  }
@@ -4450,16 +4499,18 @@ var magicLinkProvider = /*#__PURE__*/Object.freeze({
4450
4499
  MagicLinkProvider: MagicLinkProvider
4451
4500
  });
4452
4501
 
4453
- class SMSProvider {
4454
- constructor(config) {
4455
- this.name = 'sms';
4502
+ class SMSProvider extends BaseAuthProvider {
4503
+ get name() {
4504
+ return 'sms';
4505
+ }
4506
+ constructor(input) {
4507
+ super(resolveProviderConfig(AuthProvider.SMS, input));
4456
4508
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
4457
4509
  // page change between sending and verifying the code. Only non-secret metadata is stored —
4458
4510
  // never the SMS code itself (see PendingVerificationStore + F-11).
4459
4511
  this.pendingVerifications = new PendingVerificationStore('sms');
4460
4512
  this.MAX_ATTEMPTS = 3;
4461
- // Initialize with config
4462
- this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, config);
4513
+ this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, this.options);
4463
4514
  }
4464
4515
  async signIn(options) {
4465
4516
  if (!(options === null || options === void 0 ? void 0 : options.phoneNumber)) {
@@ -4697,14 +4748,9 @@ class SMSProvider {
4697
4748
  // SMS auth is supported if we have the required config
4698
4749
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
4699
4750
  }
4700
- async linkAccount(_options) {
4701
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for SMS authentication');
4702
- }
4703
- async unlinkAccount(_options) {
4704
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for SMS authentication');
4705
- }
4751
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
4706
4752
  async revokeAccess(_token) {
4707
- // SMS auth doesn't have persistent access to revoke
4753
+ // SMS auth doesn't have persistent access to revoke; clear any pending verification.
4708
4754
  this.pendingVerifications.clear();
4709
4755
  }
4710
4756
  }
@@ -4714,20 +4760,23 @@ var smsProvider = /*#__PURE__*/Object.freeze({
4714
4760
  SMSProvider: SMSProvider
4715
4761
  });
4716
4762
 
4717
- class EmailPasswordProvider {
4718
- constructor(config) {
4719
- this.name = 'email-password';
4720
- this.currentUser = null;
4763
+ class EmailPasswordProvider extends BaseAuthProvider {
4764
+ get name() {
4765
+ return 'email-password';
4766
+ }
4767
+ constructor(input) {
4768
+ super(resolveProviderConfig(AuthProvider.EMAIL_PASSWORD, input));
4769
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
4770
+ // so email/password sessions stay in-memory exactly as before (no new storage persistence).
4721
4771
  this.authToken = null;
4722
4772
  this.refreshTokenValue = null;
4723
- // Initialize with config
4724
4773
  this.config = Object.assign({ allowSignUp: true, passwordRequirements: {
4725
4774
  minLength: 8,
4726
4775
  requireUppercase: true,
4727
4776
  requireLowercase: true,
4728
4777
  requireNumbers: true,
4729
4778
  requireSpecialChars: false,
4730
- } }, config);
4779
+ } }, this.options);
4731
4780
  }
4732
4781
  async signIn(options) {
4733
4782
  if (!(options === null || options === void 0 ? void 0 : options.email) || !(options === null || options === void 0 ? void 0 : options.password)) {
@@ -4797,7 +4846,7 @@ class EmailPasswordProvider {
4797
4846
  catch (error) {
4798
4847
  if (error instanceof AuthError)
4799
4848
  throw error;
4800
- 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');
4801
4850
  }
4802
4851
  }
4803
4852
  async signUp(options) {
@@ -4882,7 +4931,7 @@ class EmailPasswordProvider {
4882
4931
  catch (error) {
4883
4932
  if (error instanceof AuthError)
4884
4933
  throw error;
4885
- 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');
4886
4935
  }
4887
4936
  }
4888
4937
  async signOut() {
@@ -4948,7 +4997,7 @@ class EmailPasswordProvider {
4948
4997
  catch (error) {
4949
4998
  if (error instanceof AuthError)
4950
4999
  throw error;
4951
- 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');
4952
5001
  }
4953
5002
  }
4954
5003
  async updatePassword(currentPassword, newPassword) {
@@ -4984,7 +5033,7 @@ class EmailPasswordProvider {
4984
5033
  catch (error) {
4985
5034
  if (error instanceof AuthError)
4986
5035
  throw error;
4987
- 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');
4988
5037
  }
4989
5038
  }
4990
5039
  async sendPasswordResetEmail(email) {
@@ -5010,7 +5059,7 @@ class EmailPasswordProvider {
5010
5059
  catch (error) {
5011
5060
  if (error instanceof AuthError)
5012
5061
  throw error;
5013
- 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');
5014
5063
  }
5015
5064
  }
5016
5065
  async sendEmailVerification() {
@@ -5039,7 +5088,7 @@ class EmailPasswordProvider {
5039
5088
  catch (error) {
5040
5089
  if (error instanceof AuthError)
5041
5090
  throw error;
5042
- 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');
5043
5092
  }
5044
5093
  }
5045
5094
  isValidEmail(email) {
@@ -5073,12 +5122,7 @@ class EmailPasswordProvider {
5073
5122
  // Email/Password auth is supported if we have the required config
5074
5123
  return !!this.config.apiUrl;
5075
5124
  }
5076
- async linkAccount(_options) {
5077
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email/password authentication');
5078
- }
5079
- async unlinkAccount(_options) {
5080
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email/password authentication');
5081
- }
5125
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
5082
5126
  async revokeAccess(_token) {
5083
5127
  // For email/password auth, revoking access means signing out
5084
5128
  await this.signOut();
@@ -5090,11 +5134,15 @@ var emailPasswordProvider = /*#__PURE__*/Object.freeze({
5090
5134
  EmailPasswordProvider: EmailPasswordProvider
5091
5135
  });
5092
5136
 
5093
- class BiometricProvider {
5094
- constructor(config = {}) {
5095
- this.name = 'biometric';
5137
+ class BiometricProvider extends BaseAuthProvider {
5138
+ get name() {
5139
+ return 'biometric';
5140
+ }
5141
+ constructor(input = {}) {
5142
+ super(resolveProviderConfig(AuthProvider.BIOMETRIC, input));
5096
5143
  this.biometricAuth = null;
5097
5144
  this.cryptoKeyPromise = null;
5145
+ const config = this.options;
5098
5146
  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);
5099
5147
  this.storageKey =
5100
5148
  config.storageKey || 'capacitor-auth-biometric-credentials';
@@ -5104,7 +5152,9 @@ class BiometricProvider {
5104
5152
  async loadBiometricPlugin() {
5105
5153
  try {
5106
5154
  // Dynamic import to avoid errors if plugin not installed
5107
- 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');
5108
5158
  this.biometricAuth = BiometricAuth;
5109
5159
  }
5110
5160
  catch (_a) {
@@ -5112,7 +5162,6 @@ class BiometricProvider {
5112
5162
  }
5113
5163
  }
5114
5164
  async signIn(_options) {
5115
- var _a, _b, _c;
5116
5165
  if (!this.biometricAuth) {
5117
5166
  throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, 'Biometric authentication plugin is not installed. Please install capacitor-biometric-authentication');
5118
5167
  }
@@ -5167,18 +5216,22 @@ class BiometricProvider {
5167
5216
  if (error instanceof AuthError)
5168
5217
  throw error;
5169
5218
  // Handle biometric errors
5170
- 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'))) {
5171
5224
  throw new AuthError(AuthErrorCode.USER_CANCELLED, 'Authentication cancelled by user');
5172
5225
  }
5173
- else if (error.code === 'biometryLockout' ||
5174
- ((_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'))) {
5175
5228
  throw new AuthError(AuthErrorCode.BIOMETRIC_LOCKOUT, 'Too many failed attempts. Biometry is locked.');
5176
5229
  }
5177
- else if (error.code === 'biometryNotEnrolled' ||
5178
- ((_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'))) {
5179
5232
  throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_ENROLLED, 'No biometric credentials are enrolled');
5180
5233
  }
5181
- throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, error.message || 'Biometric authentication failed');
5234
+ throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, errorMessage || 'Biometric authentication failed');
5182
5235
  }
5183
5236
  }
5184
5237
  async signOut() {
@@ -5378,9 +5431,7 @@ class BiometricProvider {
5378
5431
  const result = await this.isAvailable();
5379
5432
  return result.available;
5380
5433
  }
5381
- async linkAccount(_options) {
5382
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for biometric authentication');
5383
- }
5434
+ // linkAccount inherits BaseAuthProvider's OPERATION_NOT_ALLOWED default (F-44).
5384
5435
  async unlinkAccount(_options) {
5385
5436
  // Unlinking biometric auth means clearing stored credentials
5386
5437
  await this.clearStoredCredentials();
@@ -5657,12 +5708,17 @@ var linkedinProvider = /*#__PURE__*/Object.freeze({
5657
5708
  LinkedInProvider: LinkedInProvider
5658
5709
  });
5659
5710
 
5660
- class UsernamePasswordProvider {
5661
- constructor(config) {
5662
- this.name = 'username-password';
5663
- this.currentUser = null;
5711
+ class UsernamePasswordProvider extends BaseAuthProvider {
5712
+ get name() {
5713
+ return 'username-password';
5714
+ }
5715
+ constructor(input) {
5716
+ super(resolveProviderConfig(AuthProvider.USERNAME_PASSWORD, input));
5717
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
5718
+ // so username/password sessions stay in-memory exactly as before (no new storage persistence).
5664
5719
  this.authToken = null;
5665
5720
  this.refreshTokenValue = null;
5721
+ const config = this.options;
5666
5722
  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);
5667
5723
  }
5668
5724
  async signIn(options) {
@@ -5734,7 +5790,7 @@ class UsernamePasswordProvider {
5734
5790
  catch (error) {
5735
5791
  if (error instanceof AuthError)
5736
5792
  throw error;
5737
- 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');
5738
5794
  }
5739
5795
  }
5740
5796
  async signUp(options) {
@@ -5826,7 +5882,7 @@ class UsernamePasswordProvider {
5826
5882
  catch (error) {
5827
5883
  if (error instanceof AuthError)
5828
5884
  throw error;
5829
- 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');
5830
5886
  }
5831
5887
  }
5832
5888
  async signOut() {
@@ -5892,7 +5948,7 @@ class UsernamePasswordProvider {
5892
5948
  catch (error) {
5893
5949
  if (error instanceof AuthError)
5894
5950
  throw error;
5895
- 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');
5896
5952
  }
5897
5953
  }
5898
5954
  async updatePassword(currentPassword, newPassword) {
@@ -5928,7 +5984,7 @@ class UsernamePasswordProvider {
5928
5984
  catch (error) {
5929
5985
  if (error instanceof AuthError)
5930
5986
  throw error;
5931
- 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');
5932
5988
  }
5933
5989
  }
5934
5990
  async checkUsernameAvailability(username) {
@@ -6007,12 +6063,7 @@ class UsernamePasswordProvider {
6007
6063
  // Username/Password auth is supported if we have the required config
6008
6064
  return !!this.config.apiUrl;
6009
6065
  }
6010
- async linkAccount(_options) {
6011
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for username/password authentication');
6012
- }
6013
- async unlinkAccount(_options) {
6014
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for username/password authentication');
6015
- }
6066
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6016
6067
  async revokeAccess(_token) {
6017
6068
  // For username/password auth, revoking access means signing out
6018
6069
  await this.signOut();
@@ -6024,15 +6075,18 @@ var usernamePasswordProvider = /*#__PURE__*/Object.freeze({
6024
6075
  UsernamePasswordProvider: UsernamePasswordProvider
6025
6076
  });
6026
6077
 
6027
- class EmailCodeProvider {
6028
- constructor(config) {
6029
- this.name = 'email-code';
6078
+ class EmailCodeProvider extends BaseAuthProvider {
6079
+ get name() {
6080
+ return 'email-code';
6081
+ }
6082
+ constructor(input) {
6083
+ super(resolveProviderConfig(AuthProvider.EMAIL_CODE, input));
6030
6084
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
6031
6085
  // page change between sending and verifying the code. Only non-secret metadata is stored —
6032
6086
  // never the verification code itself (see PendingVerificationStore + F-11).
6033
6087
  this.pendingVerifications = new PendingVerificationStore('email-code');
6034
6088
  this.MAX_ATTEMPTS = 3;
6035
- this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, config);
6089
+ this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, this.options);
6036
6090
  }
6037
6091
  async signIn(options) {
6038
6092
  if (!(options === null || options === void 0 ? void 0 : options.email)) {
@@ -6227,12 +6281,7 @@ class EmailCodeProvider {
6227
6281
  async isSupported() {
6228
6282
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
6229
6283
  }
6230
- async linkAccount(_options) {
6231
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email code authentication');
6232
- }
6233
- async unlinkAccount(_options) {
6234
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email code authentication');
6235
- }
6284
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6236
6285
  async revokeAccess(_token) {
6237
6286
  this.pendingVerifications.clear();
6238
6287
  }
@@ -6277,11 +6326,15 @@ var emailCodeProvider = /*#__PURE__*/Object.freeze({
6277
6326
  EmailCodeProvider: EmailCodeProvider
6278
6327
  });
6279
6328
 
6280
- class PhonePasswordProvider {
6281
- constructor(config) {
6282
- this.name = 'phone-password';
6329
+ class PhonePasswordProvider extends BaseAuthProvider {
6330
+ get name() {
6331
+ return 'phone-password';
6332
+ }
6333
+ constructor(input) {
6334
+ super(resolveProviderConfig(AuthProvider.PHONE_PASSWORD, input));
6283
6335
  this.pendingVerifications = new Map();
6284
- this.currentUser = null;
6336
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
6337
+ // so phone/password sessions stay in-memory exactly as before (no new storage persistence).
6285
6338
  this.storedAccessToken = null;
6286
6339
  this.storedRefreshToken = null;
6287
6340
  this.config = Object.assign({ countryCode: '+1', requirePhoneVerification: false, passwordStrength: {
@@ -6290,7 +6343,7 @@ class PhonePasswordProvider {
6290
6343
  requireLowercase: true,
6291
6344
  requireNumbers: true,
6292
6345
  requireSpecialChars: false,
6293
- } }, config);
6346
+ } }, this.options);
6294
6347
  }
6295
6348
  async signIn(options) {
6296
6349
  const credentials = options === null || options === void 0 ? void 0 : options.credentials;
@@ -6333,12 +6386,12 @@ class PhonePasswordProvider {
6333
6386
  throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
6334
6387
  }
6335
6388
  const data = await response.json();
6336
- return this.createAuthResult(data, phoneNumber);
6389
+ return this.buildAuthResult(data, phoneNumber);
6337
6390
  }
6338
6391
  catch (error) {
6339
6392
  if (error instanceof AuthError)
6340
6393
  throw error;
6341
- 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');
6342
6395
  }
6343
6396
  }
6344
6397
  async signUp(phoneNumber, password) {
@@ -6397,12 +6450,12 @@ class PhonePasswordProvider {
6397
6450
  },
6398
6451
  };
6399
6452
  }
6400
- return this.createAuthResult(data, phoneNumber, true);
6453
+ return this.buildAuthResult(data, phoneNumber, true);
6401
6454
  }
6402
6455
  catch (error) {
6403
6456
  if (error instanceof AuthError)
6404
6457
  throw error;
6405
- 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');
6406
6459
  }
6407
6460
  }
6408
6461
  async sendVerificationCode(phoneNumber) {
@@ -6465,12 +6518,12 @@ class PhonePasswordProvider {
6465
6518
  }
6466
6519
  const data = await response.json();
6467
6520
  this.pendingVerifications.delete(phoneNumber);
6468
- return this.createAuthResult(data, phoneNumber);
6521
+ return this.buildAuthResult(data, phoneNumber);
6469
6522
  }
6470
6523
  catch (error) {
6471
6524
  if (error instanceof AuthError)
6472
6525
  throw error;
6473
- throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error.message || 'Phone verification failed');
6526
+ throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Phone verification failed');
6474
6527
  }
6475
6528
  }
6476
6529
  async signOut() {
@@ -6526,7 +6579,7 @@ class PhonePasswordProvider {
6526
6579
  catch (error) {
6527
6580
  if (error instanceof AuthError)
6528
6581
  throw error;
6529
- 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');
6530
6583
  }
6531
6584
  }
6532
6585
  async initialize() {
@@ -6535,12 +6588,7 @@ class PhonePasswordProvider {
6535
6588
  async isSupported() {
6536
6589
  return !!(this.config.signInUrl && this.config.signUpUrl);
6537
6590
  }
6538
- async linkAccount(_options) {
6539
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for phone/password authentication');
6540
- }
6541
- async unlinkAccount(_options) {
6542
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for phone/password authentication');
6543
- }
6591
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6544
6592
  async revokeAccess(_token) {
6545
6593
  await this.signOut();
6546
6594
  }
@@ -6567,7 +6615,10 @@ class PhonePasswordProvider {
6567
6615
  throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset');
6568
6616
  }
6569
6617
  }
6570
- createAuthResult(data, phoneNumber, isNewUser = false) {
6618
+ // Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
6619
+ // which has a different signature (this builds a phone-specific result from a backend payload).
6620
+ buildAuthResult(data, phoneNumber, isNewUser = false) {
6621
+ var _a, _b;
6571
6622
  const user = {
6572
6623
  uid: data.uid || this.generateUid(phoneNumber),
6573
6624
  email: data.email || null,
@@ -6591,8 +6642,8 @@ class PhonePasswordProvider {
6591
6642
  },
6592
6643
  };
6593
6644
  this.currentUser = user;
6594
- this.storedAccessToken = data.accessToken;
6595
- 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;
6596
6647
  return {
6597
6648
  user,
6598
6649
  credential: {