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/react.cjs.js CHANGED
@@ -622,6 +622,27 @@ class PlatformDetector {
622
622
  }
623
623
  PlatformDetector.platformInfo = null;
624
624
 
625
+ /**
626
+ * Safely extract a human-readable message from an unknown thrown value.
627
+ *
628
+ * `catch` clauses receive `unknown` (the honest type — anything can be thrown), so reach for this
629
+ * instead of typing the binding as `any`. Returns `undefined` when no message can be derived, so
630
+ * callers can fall back to their own default text: `getErrorMessage(error) || 'Default message'`.
631
+ */
632
+ function getErrorMessage(error) {
633
+ if (error instanceof Error) {
634
+ return error.message;
635
+ }
636
+ if (typeof error === 'object' && error !== null && 'message' in error) {
637
+ const message = error.message;
638
+ return typeof message === 'string' ? message : undefined;
639
+ }
640
+ if (typeof error === 'string') {
641
+ return error;
642
+ }
643
+ return undefined;
644
+ }
645
+
625
646
  /**
626
647
  * Built-in provider manifests (display metadata + human-readable setup instructions).
627
648
  *
@@ -1109,7 +1130,7 @@ class ProviderRegistry {
1109
1130
  return (_b = this.NAME_ALIASES[name]) !== null && _b !== void 0 ? _b : name;
1110
1131
  }
1111
1132
  static async getProvider(name, options, deps) {
1112
- var _b, _c, _d, _e;
1133
+ var _b, _c;
1113
1134
  const key = this.canonicalName(name);
1114
1135
  // Check if already loaded
1115
1136
  const existing = this.providers.get(key);
@@ -1134,7 +1155,9 @@ class ProviderRegistry {
1134
1155
  }
1135
1156
  }
1136
1157
  try {
1137
- // Load the provider class
1158
+ // Load the provider class. Every loader resolves to `{ default: <ProviderConstructor> }`
1159
+ // (see registerLoader calls above); narrow `default` to that constructor shape so the
1160
+ // `new ProviderClass(...)` below type-checks without resorting to `any`.
1138
1161
  const module = await loader();
1139
1162
  const ProviderClass = module.default;
1140
1163
  // Build the constructor argument. BaseAuthProvider subclasses need a full
@@ -1167,8 +1190,9 @@ class ProviderRegistry {
1167
1190
  }
1168
1191
  catch (error) {
1169
1192
  // Check if it's a missing dependency error
1170
- if (((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot find module')) ||
1171
- ((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to resolve module'))) {
1193
+ const message = getErrorMessage(error);
1194
+ if ((message === null || message === void 0 ? void 0 : message.includes('Cannot find module')) ||
1195
+ (message === null || message === void 0 ? void 0 : message.includes('Failed to resolve module'))) {
1172
1196
  const manifest = this.manifests.get(this.canonicalName(name));
1173
1197
  if (manifest === null || manifest === void 0 ? void 0 : manifest.packageName) {
1174
1198
  throw new Error(`Missing dependency for ${manifest.displayName} provider.\n\n` +
@@ -1421,6 +1445,8 @@ class AuthManagerCore {
1421
1445
  // email/password/phoneNumber/username) AND kept nested under `credentials` for
1422
1446
  // providers that read them there.
1423
1447
  this.logger.info(`Signing in with ${providerName}`);
1448
+ // The provider reads credentials/options from this merged shape; `provider` is supplied via
1449
+ // construction, not here, so we assert to SignInOptions (whose `provider` is required).
1424
1450
  const result = await provider.signIn(Object.assign(Object.assign(Object.assign({}, signInOptions.options), ((_b = signInOptions.credentials) !== null && _b !== void 0 ? _b : {})), { credentials: signInOptions.credentials }));
1425
1451
  // Update state
1426
1452
  this.updateState({
@@ -2141,6 +2167,31 @@ function useIsAuthenticated() {
2141
2167
  return isAuthenticated;
2142
2168
  }
2143
2169
 
2170
+ /**
2171
+ * Normalize a provider constructor argument into a full {@link BaseProviderConfig}.
2172
+ *
2173
+ * The standalone providers are public (exported from `capacitor-auth-manager/providers/web`) and
2174
+ * get constructed two ways: the factory/registry pass a full {@link BaseProviderConfig}, while
2175
+ * tests and direct consumers pass the provider's own bare options object. This helper accepts
2176
+ * either — a bare object is wrapped with an in-memory storage (`AuthPersistence.NONE`, so it never
2177
+ * touches `window` and stays safe under SSR / Node test environments) plus the shared
2178
+ * {@link defaultLogger}. Callers that pass a full config keep their injected storage/logger.
2179
+ */
2180
+ function resolveProviderConfig(provider, input) {
2181
+ if (typeof input === 'object' &&
2182
+ input !== null &&
2183
+ 'storage' in input &&
2184
+ 'logger' in input &&
2185
+ 'options' in input) {
2186
+ return input;
2187
+ }
2188
+ return {
2189
+ provider,
2190
+ options: (input !== null && input !== void 0 ? input : {}),
2191
+ storage: new WebStorage(AuthPersistence.NONE),
2192
+ logger: defaultLogger,
2193
+ };
2194
+ }
2144
2195
  class BaseAuthProvider {
2145
2196
  get name() {
2146
2197
  return this.provider;
@@ -2160,13 +2211,13 @@ class BaseAuthProvider {
2160
2211
  // across every provider (see AuthProviderInterface, where they are optional). Marking them
2161
2212
  // abstract previously forced every subclass to re-implement them just to throw.
2162
2213
  async linkAccount(_options) {
2163
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account linking`, this.provider);
2214
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account linking is not supported by provider ${this.provider}`, this.provider);
2164
2215
  }
2165
2216
  async unlinkAccount(_options) {
2166
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account unlinking`, this.provider);
2217
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account unlinking is not supported by provider ${this.provider}`, this.provider);
2167
2218
  }
2168
2219
  async revokeAccess(_token) {
2169
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support access revocation`, this.provider);
2220
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Access revocation is not supported by provider ${this.provider}`, this.provider);
2170
2221
  }
2171
2222
  async getCurrentUser() {
2172
2223
  if (!this.isInitialized) {
@@ -4481,16 +4532,19 @@ class PendingVerificationStore {
4481
4532
  }
4482
4533
  }
4483
4534
 
4484
- class MagicLinkProvider {
4485
- constructor(config) {
4486
- this.name = 'magic-link';
4535
+ class MagicLinkProvider extends BaseAuthProvider {
4536
+ get name() {
4537
+ return 'magic-link';
4538
+ }
4539
+ constructor(input) {
4540
+ super(resolveProviderConfig(AuthProvider.EMAIL_MAGIC_LINK, input));
4487
4541
  // Persisted (SSR-guarded localStorage) so a magic link clicked from an email — which opens a
4488
4542
  // FRESH page load with empty in-memory state — can still find its pending entry to verify
4489
4543
  // against. Keyed by the link token (already present in the callback URL); we store only the
4490
4544
  // email + expiry, never any additional secret (see PendingVerificationStore + F-11).
4491
4545
  this.pendingVerification = new PendingVerificationStore('magic-link');
4492
- // Initialize with config
4493
- this.config = config;
4546
+ // Magic link uses its config as-is (no defaults to merge).
4547
+ this.config = this.options;
4494
4548
  // Check for magic link callback on initialization
4495
4549
  this.checkForMagicLinkCallback();
4496
4550
  }
@@ -4740,14 +4794,9 @@ class MagicLinkProvider {
4740
4794
  // Magic link auth is supported if we have the required config
4741
4795
  return !!this.config.sendLinkUrl;
4742
4796
  }
4743
- async linkAccount(_options) {
4744
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for magic link authentication');
4745
- }
4746
- async unlinkAccount(_options) {
4747
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for magic link authentication');
4748
- }
4797
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
4749
4798
  async revokeAccess(_token) {
4750
- // Magic link doesn't have persistent access to revoke
4799
+ // Magic link doesn't have persistent access to revoke; clear any pending verification.
4751
4800
  this.pendingVerification.clear();
4752
4801
  }
4753
4802
  }
@@ -4757,16 +4806,18 @@ var magicLinkProvider = /*#__PURE__*/Object.freeze({
4757
4806
  MagicLinkProvider: MagicLinkProvider
4758
4807
  });
4759
4808
 
4760
- class SMSProvider {
4761
- constructor(config) {
4762
- this.name = 'sms';
4809
+ class SMSProvider extends BaseAuthProvider {
4810
+ get name() {
4811
+ return 'sms';
4812
+ }
4813
+ constructor(input) {
4814
+ super(resolveProviderConfig(AuthProvider.SMS, input));
4763
4815
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
4764
4816
  // page change between sending and verifying the code. Only non-secret metadata is stored —
4765
4817
  // never the SMS code itself (see PendingVerificationStore + F-11).
4766
4818
  this.pendingVerifications = new PendingVerificationStore('sms');
4767
4819
  this.MAX_ATTEMPTS = 3;
4768
- // Initialize with config
4769
- this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, config);
4820
+ this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, this.options);
4770
4821
  }
4771
4822
  async signIn(options) {
4772
4823
  if (!(options === null || options === void 0 ? void 0 : options.phoneNumber)) {
@@ -5004,14 +5055,9 @@ class SMSProvider {
5004
5055
  // SMS auth is supported if we have the required config
5005
5056
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
5006
5057
  }
5007
- async linkAccount(_options) {
5008
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for SMS authentication');
5009
- }
5010
- async unlinkAccount(_options) {
5011
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for SMS authentication');
5012
- }
5058
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
5013
5059
  async revokeAccess(_token) {
5014
- // SMS auth doesn't have persistent access to revoke
5060
+ // SMS auth doesn't have persistent access to revoke; clear any pending verification.
5015
5061
  this.pendingVerifications.clear();
5016
5062
  }
5017
5063
  }
@@ -5021,20 +5067,23 @@ var smsProvider = /*#__PURE__*/Object.freeze({
5021
5067
  SMSProvider: SMSProvider
5022
5068
  });
5023
5069
 
5024
- class EmailPasswordProvider {
5025
- constructor(config) {
5026
- this.name = 'email-password';
5027
- this.currentUser = null;
5070
+ class EmailPasswordProvider extends BaseAuthProvider {
5071
+ get name() {
5072
+ return 'email-password';
5073
+ }
5074
+ constructor(input) {
5075
+ super(resolveProviderConfig(AuthProvider.EMAIL_PASSWORD, input));
5076
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
5077
+ // so email/password sessions stay in-memory exactly as before (no new storage persistence).
5028
5078
  this.authToken = null;
5029
5079
  this.refreshTokenValue = null;
5030
- // Initialize with config
5031
5080
  this.config = Object.assign({ allowSignUp: true, passwordRequirements: {
5032
5081
  minLength: 8,
5033
5082
  requireUppercase: true,
5034
5083
  requireLowercase: true,
5035
5084
  requireNumbers: true,
5036
5085
  requireSpecialChars: false,
5037
- } }, config);
5086
+ } }, this.options);
5038
5087
  }
5039
5088
  async signIn(options) {
5040
5089
  if (!(options === null || options === void 0 ? void 0 : options.email) || !(options === null || options === void 0 ? void 0 : options.password)) {
@@ -5104,7 +5153,7 @@ class EmailPasswordProvider {
5104
5153
  catch (error) {
5105
5154
  if (error instanceof AuthError)
5106
5155
  throw error;
5107
- throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Failed to sign in with email and password');
5156
+ throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with email and password');
5108
5157
  }
5109
5158
  }
5110
5159
  async signUp(options) {
@@ -5189,7 +5238,7 @@ class EmailPasswordProvider {
5189
5238
  catch (error) {
5190
5239
  if (error instanceof AuthError)
5191
5240
  throw error;
5192
- throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error.message || 'Failed to create account');
5241
+ throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
5193
5242
  }
5194
5243
  }
5195
5244
  async signOut() {
@@ -5255,7 +5304,7 @@ class EmailPasswordProvider {
5255
5304
  catch (error) {
5256
5305
  if (error instanceof AuthError)
5257
5306
  throw error;
5258
- throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Failed to refresh token');
5307
+ throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
5259
5308
  }
5260
5309
  }
5261
5310
  async updatePassword(currentPassword, newPassword) {
@@ -5291,7 +5340,7 @@ class EmailPasswordProvider {
5291
5340
  catch (error) {
5292
5341
  if (error instanceof AuthError)
5293
5342
  throw error;
5294
- throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to update password');
5343
+ throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
5295
5344
  }
5296
5345
  }
5297
5346
  async sendPasswordResetEmail(email) {
@@ -5317,7 +5366,7 @@ class EmailPasswordProvider {
5317
5366
  catch (error) {
5318
5367
  if (error instanceof AuthError)
5319
5368
  throw error;
5320
- throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset email');
5369
+ throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to send password reset email');
5321
5370
  }
5322
5371
  }
5323
5372
  async sendEmailVerification() {
@@ -5346,7 +5395,7 @@ class EmailPasswordProvider {
5346
5395
  catch (error) {
5347
5396
  if (error instanceof AuthError)
5348
5397
  throw error;
5349
- throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error.message || 'Failed to send verification email');
5398
+ throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Failed to send verification email');
5350
5399
  }
5351
5400
  }
5352
5401
  isValidEmail(email) {
@@ -5380,12 +5429,7 @@ class EmailPasswordProvider {
5380
5429
  // Email/Password auth is supported if we have the required config
5381
5430
  return !!this.config.apiUrl;
5382
5431
  }
5383
- async linkAccount(_options) {
5384
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email/password authentication');
5385
- }
5386
- async unlinkAccount(_options) {
5387
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email/password authentication');
5388
- }
5432
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
5389
5433
  async revokeAccess(_token) {
5390
5434
  // For email/password auth, revoking access means signing out
5391
5435
  await this.signOut();
@@ -5397,11 +5441,15 @@ var emailPasswordProvider = /*#__PURE__*/Object.freeze({
5397
5441
  EmailPasswordProvider: EmailPasswordProvider
5398
5442
  });
5399
5443
 
5400
- class BiometricProvider {
5401
- constructor(config = {}) {
5402
- this.name = 'biometric';
5444
+ class BiometricProvider extends BaseAuthProvider {
5445
+ get name() {
5446
+ return 'biometric';
5447
+ }
5448
+ constructor(input = {}) {
5449
+ super(resolveProviderConfig(AuthProvider.BIOMETRIC, input));
5403
5450
  this.biometricAuth = null;
5404
5451
  this.cryptoKeyPromise = null;
5452
+ const config = this.options;
5405
5453
  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);
5406
5454
  this.storageKey =
5407
5455
  config.storageKey || 'capacitor-auth-biometric-credentials';
@@ -5411,7 +5459,9 @@ class BiometricProvider {
5411
5459
  async loadBiometricPlugin() {
5412
5460
  try {
5413
5461
  // Dynamic import to avoid errors if plugin not installed
5414
- const { BiometricAuth } = await import('capacitor-biometric-authentication');
5462
+ const { BiometricAuth } = await import(
5463
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- optional peer dep; module may be absent at build time
5464
+ 'capacitor-biometric-authentication');
5415
5465
  this.biometricAuth = BiometricAuth;
5416
5466
  }
5417
5467
  catch (_a) {
@@ -5419,7 +5469,6 @@ class BiometricProvider {
5419
5469
  }
5420
5470
  }
5421
5471
  async signIn(_options) {
5422
- var _a, _b, _c;
5423
5472
  if (!this.biometricAuth) {
5424
5473
  throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, 'Biometric authentication plugin is not installed. Please install capacitor-biometric-authentication');
5425
5474
  }
@@ -5474,18 +5523,22 @@ class BiometricProvider {
5474
5523
  if (error instanceof AuthError)
5475
5524
  throw error;
5476
5525
  // Handle biometric errors
5477
- if (error.code === 'userCancel' || ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('cancel'))) {
5526
+ const errorCode = typeof error === 'object' && error !== null && 'code' in error
5527
+ ? error.code
5528
+ : undefined;
5529
+ const errorMessage = getErrorMessage(error);
5530
+ if (errorCode === 'userCancel' || (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('cancel'))) {
5478
5531
  throw new AuthError(AuthErrorCode.USER_CANCELLED, 'Authentication cancelled by user');
5479
5532
  }
5480
- else if (error.code === 'biometryLockout' ||
5481
- ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('lockout'))) {
5533
+ else if (errorCode === 'biometryLockout' ||
5534
+ (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('lockout'))) {
5482
5535
  throw new AuthError(AuthErrorCode.BIOMETRIC_LOCKOUT, 'Too many failed attempts. Biometry is locked.');
5483
5536
  }
5484
- else if (error.code === 'biometryNotEnrolled' ||
5485
- ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('enrolled'))) {
5537
+ else if (errorCode === 'biometryNotEnrolled' ||
5538
+ (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('enrolled'))) {
5486
5539
  throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_ENROLLED, 'No biometric credentials are enrolled');
5487
5540
  }
5488
- throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, error.message || 'Biometric authentication failed');
5541
+ throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, errorMessage || 'Biometric authentication failed');
5489
5542
  }
5490
5543
  }
5491
5544
  async signOut() {
@@ -5685,9 +5738,7 @@ class BiometricProvider {
5685
5738
  const result = await this.isAvailable();
5686
5739
  return result.available;
5687
5740
  }
5688
- async linkAccount(_options) {
5689
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for biometric authentication');
5690
- }
5741
+ // linkAccount inherits BaseAuthProvider's OPERATION_NOT_ALLOWED default (F-44).
5691
5742
  async unlinkAccount(_options) {
5692
5743
  // Unlinking biometric auth means clearing stored credentials
5693
5744
  await this.clearStoredCredentials();
@@ -5964,12 +6015,17 @@ var linkedinProvider = /*#__PURE__*/Object.freeze({
5964
6015
  LinkedInProvider: LinkedInProvider
5965
6016
  });
5966
6017
 
5967
- class UsernamePasswordProvider {
5968
- constructor(config) {
5969
- this.name = 'username-password';
5970
- this.currentUser = null;
6018
+ class UsernamePasswordProvider extends BaseAuthProvider {
6019
+ get name() {
6020
+ return 'username-password';
6021
+ }
6022
+ constructor(input) {
6023
+ super(resolveProviderConfig(AuthProvider.USERNAME_PASSWORD, input));
6024
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
6025
+ // so username/password sessions stay in-memory exactly as before (no new storage persistence).
5971
6026
  this.authToken = null;
5972
6027
  this.refreshTokenValue = null;
6028
+ const config = this.options;
5973
6029
  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);
5974
6030
  }
5975
6031
  async signIn(options) {
@@ -6041,7 +6097,7 @@ class UsernamePasswordProvider {
6041
6097
  catch (error) {
6042
6098
  if (error instanceof AuthError)
6043
6099
  throw error;
6044
- throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Failed to sign in with username and password');
6100
+ throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with username and password');
6045
6101
  }
6046
6102
  }
6047
6103
  async signUp(options) {
@@ -6133,7 +6189,7 @@ class UsernamePasswordProvider {
6133
6189
  catch (error) {
6134
6190
  if (error instanceof AuthError)
6135
6191
  throw error;
6136
- throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error.message || 'Failed to create account');
6192
+ throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
6137
6193
  }
6138
6194
  }
6139
6195
  async signOut() {
@@ -6199,7 +6255,7 @@ class UsernamePasswordProvider {
6199
6255
  catch (error) {
6200
6256
  if (error instanceof AuthError)
6201
6257
  throw error;
6202
- throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Failed to refresh token');
6258
+ throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
6203
6259
  }
6204
6260
  }
6205
6261
  async updatePassword(currentPassword, newPassword) {
@@ -6235,7 +6291,7 @@ class UsernamePasswordProvider {
6235
6291
  catch (error) {
6236
6292
  if (error instanceof AuthError)
6237
6293
  throw error;
6238
- throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to update password');
6294
+ throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
6239
6295
  }
6240
6296
  }
6241
6297
  async checkUsernameAvailability(username) {
@@ -6314,12 +6370,7 @@ class UsernamePasswordProvider {
6314
6370
  // Username/Password auth is supported if we have the required config
6315
6371
  return !!this.config.apiUrl;
6316
6372
  }
6317
- async linkAccount(_options) {
6318
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for username/password authentication');
6319
- }
6320
- async unlinkAccount(_options) {
6321
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for username/password authentication');
6322
- }
6373
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6323
6374
  async revokeAccess(_token) {
6324
6375
  // For username/password auth, revoking access means signing out
6325
6376
  await this.signOut();
@@ -6331,15 +6382,18 @@ var usernamePasswordProvider = /*#__PURE__*/Object.freeze({
6331
6382
  UsernamePasswordProvider: UsernamePasswordProvider
6332
6383
  });
6333
6384
 
6334
- class EmailCodeProvider {
6335
- constructor(config) {
6336
- this.name = 'email-code';
6385
+ class EmailCodeProvider extends BaseAuthProvider {
6386
+ get name() {
6387
+ return 'email-code';
6388
+ }
6389
+ constructor(input) {
6390
+ super(resolveProviderConfig(AuthProvider.EMAIL_CODE, input));
6337
6391
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
6338
6392
  // page change between sending and verifying the code. Only non-secret metadata is stored —
6339
6393
  // never the verification code itself (see PendingVerificationStore + F-11).
6340
6394
  this.pendingVerifications = new PendingVerificationStore('email-code');
6341
6395
  this.MAX_ATTEMPTS = 3;
6342
- this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, config);
6396
+ this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, this.options);
6343
6397
  }
6344
6398
  async signIn(options) {
6345
6399
  if (!(options === null || options === void 0 ? void 0 : options.email)) {
@@ -6534,12 +6588,7 @@ class EmailCodeProvider {
6534
6588
  async isSupported() {
6535
6589
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
6536
6590
  }
6537
- async linkAccount(_options) {
6538
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email code authentication');
6539
- }
6540
- async unlinkAccount(_options) {
6541
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email code authentication');
6542
- }
6591
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6543
6592
  async revokeAccess(_token) {
6544
6593
  this.pendingVerifications.clear();
6545
6594
  }
@@ -6584,11 +6633,15 @@ var emailCodeProvider = /*#__PURE__*/Object.freeze({
6584
6633
  EmailCodeProvider: EmailCodeProvider
6585
6634
  });
6586
6635
 
6587
- class PhonePasswordProvider {
6588
- constructor(config) {
6589
- this.name = 'phone-password';
6636
+ class PhonePasswordProvider extends BaseAuthProvider {
6637
+ get name() {
6638
+ return 'phone-password';
6639
+ }
6640
+ constructor(input) {
6641
+ super(resolveProviderConfig(AuthProvider.PHONE_PASSWORD, input));
6590
6642
  this.pendingVerifications = new Map();
6591
- this.currentUser = null;
6643
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
6644
+ // so phone/password sessions stay in-memory exactly as before (no new storage persistence).
6592
6645
  this.storedAccessToken = null;
6593
6646
  this.storedRefreshToken = null;
6594
6647
  this.config = Object.assign({ countryCode: '+1', requirePhoneVerification: false, passwordStrength: {
@@ -6597,7 +6650,7 @@ class PhonePasswordProvider {
6597
6650
  requireLowercase: true,
6598
6651
  requireNumbers: true,
6599
6652
  requireSpecialChars: false,
6600
- } }, config);
6653
+ } }, this.options);
6601
6654
  }
6602
6655
  async signIn(options) {
6603
6656
  const credentials = options === null || options === void 0 ? void 0 : options.credentials;
@@ -6640,12 +6693,12 @@ class PhonePasswordProvider {
6640
6693
  throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
6641
6694
  }
6642
6695
  const data = await response.json();
6643
- return this.createAuthResult(data, phoneNumber);
6696
+ return this.buildAuthResult(data, phoneNumber);
6644
6697
  }
6645
6698
  catch (error) {
6646
6699
  if (error instanceof AuthError)
6647
6700
  throw error;
6648
- throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
6701
+ throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Sign in failed');
6649
6702
  }
6650
6703
  }
6651
6704
  async signUp(phoneNumber, password) {
@@ -6704,12 +6757,12 @@ class PhonePasswordProvider {
6704
6757
  },
6705
6758
  };
6706
6759
  }
6707
- return this.createAuthResult(data, phoneNumber, true);
6760
+ return this.buildAuthResult(data, phoneNumber, true);
6708
6761
  }
6709
6762
  catch (error) {
6710
6763
  if (error instanceof AuthError)
6711
6764
  throw error;
6712
- throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error.message || 'Sign up failed');
6765
+ throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Sign up failed');
6713
6766
  }
6714
6767
  }
6715
6768
  async sendVerificationCode(phoneNumber) {
@@ -6772,12 +6825,12 @@ class PhonePasswordProvider {
6772
6825
  }
6773
6826
  const data = await response.json();
6774
6827
  this.pendingVerifications.delete(phoneNumber);
6775
- return this.createAuthResult(data, phoneNumber);
6828
+ return this.buildAuthResult(data, phoneNumber);
6776
6829
  }
6777
6830
  catch (error) {
6778
6831
  if (error instanceof AuthError)
6779
6832
  throw error;
6780
- throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error.message || 'Phone verification failed');
6833
+ throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Phone verification failed');
6781
6834
  }
6782
6835
  }
6783
6836
  async signOut() {
@@ -6833,7 +6886,7 @@ class PhonePasswordProvider {
6833
6886
  catch (error) {
6834
6887
  if (error instanceof AuthError)
6835
6888
  throw error;
6836
- throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Token refresh failed');
6889
+ throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Token refresh failed');
6837
6890
  }
6838
6891
  }
6839
6892
  async initialize() {
@@ -6842,12 +6895,7 @@ class PhonePasswordProvider {
6842
6895
  async isSupported() {
6843
6896
  return !!(this.config.signInUrl && this.config.signUpUrl);
6844
6897
  }
6845
- async linkAccount(_options) {
6846
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for phone/password authentication');
6847
- }
6848
- async unlinkAccount(_options) {
6849
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for phone/password authentication');
6850
- }
6898
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6851
6899
  async revokeAccess(_token) {
6852
6900
  await this.signOut();
6853
6901
  }
@@ -6874,7 +6922,10 @@ class PhonePasswordProvider {
6874
6922
  throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset');
6875
6923
  }
6876
6924
  }
6877
- createAuthResult(data, phoneNumber, isNewUser = false) {
6925
+ // Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
6926
+ // which has a different signature (this builds a phone-specific result from a backend payload).
6927
+ buildAuthResult(data, phoneNumber, isNewUser = false) {
6928
+ var _a, _b;
6878
6929
  const user = {
6879
6930
  uid: data.uid || this.generateUid(phoneNumber),
6880
6931
  email: data.email || null,
@@ -6898,8 +6949,8 @@ class PhonePasswordProvider {
6898
6949
  },
6899
6950
  };
6900
6951
  this.currentUser = user;
6901
- this.storedAccessToken = data.accessToken;
6902
- this.storedRefreshToken = data.refreshToken;
6952
+ this.storedAccessToken = (_a = data.accessToken) !== null && _a !== void 0 ? _a : null;
6953
+ this.storedRefreshToken = (_b = data.refreshToken) !== null && _b !== void 0 ? _b : null;
6903
6954
  return {
6904
6955
  user,
6905
6956
  credential: {