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
@@ -626,6 +626,27 @@ class PlatformDetector {
626
626
  }
627
627
  PlatformDetector.platformInfo = null;
628
628
 
629
+ /**
630
+ * Safely extract a human-readable message from an unknown thrown value.
631
+ *
632
+ * `catch` clauses receive `unknown` (the honest type — anything can be thrown), so reach for this
633
+ * instead of typing the binding as `any`. Returns `undefined` when no message can be derived, so
634
+ * callers can fall back to their own default text: `getErrorMessage(error) || 'Default message'`.
635
+ */
636
+ function getErrorMessage(error) {
637
+ if (error instanceof Error) {
638
+ return error.message;
639
+ }
640
+ if (typeof error === 'object' && error !== null && 'message' in error) {
641
+ const message = error.message;
642
+ return typeof message === 'string' ? message : undefined;
643
+ }
644
+ if (typeof error === 'string') {
645
+ return error;
646
+ }
647
+ return undefined;
648
+ }
649
+
629
650
  /**
630
651
  * Built-in provider manifests (display metadata + human-readable setup instructions).
631
652
  *
@@ -1113,7 +1134,7 @@ class ProviderRegistry {
1113
1134
  return (_b = this.NAME_ALIASES[name]) !== null && _b !== void 0 ? _b : name;
1114
1135
  }
1115
1136
  static async getProvider(name, options, deps) {
1116
- var _b, _c, _d, _e;
1137
+ var _b, _c;
1117
1138
  const key = this.canonicalName(name);
1118
1139
  // Check if already loaded
1119
1140
  const existing = this.providers.get(key);
@@ -1138,7 +1159,9 @@ class ProviderRegistry {
1138
1159
  }
1139
1160
  }
1140
1161
  try {
1141
- // Load the provider class
1162
+ // Load the provider class. Every loader resolves to `{ default: <ProviderConstructor> }`
1163
+ // (see registerLoader calls above); narrow `default` to that constructor shape so the
1164
+ // `new ProviderClass(...)` below type-checks without resorting to `any`.
1142
1165
  const module = await loader();
1143
1166
  const ProviderClass = module.default;
1144
1167
  // Build the constructor argument. BaseAuthProvider subclasses need a full
@@ -1171,8 +1194,9 @@ class ProviderRegistry {
1171
1194
  }
1172
1195
  catch (error) {
1173
1196
  // Check if it's a missing dependency error
1174
- if (((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot find module')) ||
1175
- ((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to resolve module'))) {
1197
+ const message = getErrorMessage(error);
1198
+ if ((message === null || message === void 0 ? void 0 : message.includes('Cannot find module')) ||
1199
+ (message === null || message === void 0 ? void 0 : message.includes('Failed to resolve module'))) {
1176
1200
  const manifest = this.manifests.get(this.canonicalName(name));
1177
1201
  if (manifest === null || manifest === void 0 ? void 0 : manifest.packageName) {
1178
1202
  throw new Error(`Missing dependency for ${manifest.displayName} provider.\n\n` +
@@ -1425,6 +1449,8 @@ class AuthManagerCore {
1425
1449
  // email/password/phoneNumber/username) AND kept nested under `credentials` for
1426
1450
  // providers that read them there.
1427
1451
  this.logger.info(`Signing in with ${providerName}`);
1452
+ // The provider reads credentials/options from this merged shape; `provider` is supplied via
1453
+ // construction, not here, so we assert to SignInOptions (whose `provider` is required).
1428
1454
  const result = await provider.signIn(Object.assign(Object.assign(Object.assign({}, signInOptions.options), ((_b = signInOptions.credentials) !== null && _b !== void 0 ? _b : {})), { credentials: signInOptions.credentials }));
1429
1455
  // Update state
1430
1456
  this.updateState({
@@ -2184,6 +2210,31 @@ let NoAuthGuard = (() => {
2184
2210
  return _classThis;
2185
2211
  })();
2186
2212
 
2213
+ /**
2214
+ * Normalize a provider constructor argument into a full {@link BaseProviderConfig}.
2215
+ *
2216
+ * The standalone providers are public (exported from `capacitor-auth-manager/providers/web`) and
2217
+ * get constructed two ways: the factory/registry pass a full {@link BaseProviderConfig}, while
2218
+ * tests and direct consumers pass the provider's own bare options object. This helper accepts
2219
+ * either — a bare object is wrapped with an in-memory storage (`AuthPersistence.NONE`, so it never
2220
+ * touches `window` and stays safe under SSR / Node test environments) plus the shared
2221
+ * {@link defaultLogger}. Callers that pass a full config keep their injected storage/logger.
2222
+ */
2223
+ function resolveProviderConfig(provider, input) {
2224
+ if (typeof input === 'object' &&
2225
+ input !== null &&
2226
+ 'storage' in input &&
2227
+ 'logger' in input &&
2228
+ 'options' in input) {
2229
+ return input;
2230
+ }
2231
+ return {
2232
+ provider,
2233
+ options: (input !== null && input !== void 0 ? input : {}),
2234
+ storage: new WebStorage(AuthPersistence.NONE),
2235
+ logger: defaultLogger,
2236
+ };
2237
+ }
2187
2238
  class BaseAuthProvider {
2188
2239
  get name() {
2189
2240
  return this.provider;
@@ -2203,13 +2254,13 @@ class BaseAuthProvider {
2203
2254
  // across every provider (see AuthProviderInterface, where they are optional). Marking them
2204
2255
  // abstract previously forced every subclass to re-implement them just to throw.
2205
2256
  async linkAccount(_options) {
2206
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account linking`, this.provider);
2257
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account linking is not supported by provider ${this.provider}`, this.provider);
2207
2258
  }
2208
2259
  async unlinkAccount(_options) {
2209
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account unlinking`, this.provider);
2260
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account unlinking is not supported by provider ${this.provider}`, this.provider);
2210
2261
  }
2211
2262
  async revokeAccess(_token) {
2212
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support access revocation`, this.provider);
2263
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Access revocation is not supported by provider ${this.provider}`, this.provider);
2213
2264
  }
2214
2265
  async getCurrentUser() {
2215
2266
  if (!this.isInitialized) {
@@ -4524,16 +4575,19 @@ class PendingVerificationStore {
4524
4575
  }
4525
4576
  }
4526
4577
 
4527
- class MagicLinkProvider {
4528
- constructor(config) {
4529
- this.name = 'magic-link';
4578
+ class MagicLinkProvider extends BaseAuthProvider {
4579
+ get name() {
4580
+ return 'magic-link';
4581
+ }
4582
+ constructor(input) {
4583
+ super(resolveProviderConfig(AuthProvider.EMAIL_MAGIC_LINK, input));
4530
4584
  // Persisted (SSR-guarded localStorage) so a magic link clicked from an email — which opens a
4531
4585
  // FRESH page load with empty in-memory state — can still find its pending entry to verify
4532
4586
  // against. Keyed by the link token (already present in the callback URL); we store only the
4533
4587
  // email + expiry, never any additional secret (see PendingVerificationStore + F-11).
4534
4588
  this.pendingVerification = new PendingVerificationStore('magic-link');
4535
- // Initialize with config
4536
- this.config = config;
4589
+ // Magic link uses its config as-is (no defaults to merge).
4590
+ this.config = this.options;
4537
4591
  // Check for magic link callback on initialization
4538
4592
  this.checkForMagicLinkCallback();
4539
4593
  }
@@ -4783,14 +4837,9 @@ class MagicLinkProvider {
4783
4837
  // Magic link auth is supported if we have the required config
4784
4838
  return !!this.config.sendLinkUrl;
4785
4839
  }
4786
- async linkAccount(_options) {
4787
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for magic link authentication');
4788
- }
4789
- async unlinkAccount(_options) {
4790
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for magic link authentication');
4791
- }
4840
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
4792
4841
  async revokeAccess(_token) {
4793
- // Magic link doesn't have persistent access to revoke
4842
+ // Magic link doesn't have persistent access to revoke; clear any pending verification.
4794
4843
  this.pendingVerification.clear();
4795
4844
  }
4796
4845
  }
@@ -4800,16 +4849,18 @@ var magicLinkProvider = /*#__PURE__*/Object.freeze({
4800
4849
  MagicLinkProvider: MagicLinkProvider
4801
4850
  });
4802
4851
 
4803
- class SMSProvider {
4804
- constructor(config) {
4805
- this.name = 'sms';
4852
+ class SMSProvider extends BaseAuthProvider {
4853
+ get name() {
4854
+ return 'sms';
4855
+ }
4856
+ constructor(input) {
4857
+ super(resolveProviderConfig(AuthProvider.SMS, input));
4806
4858
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
4807
4859
  // page change between sending and verifying the code. Only non-secret metadata is stored —
4808
4860
  // never the SMS code itself (see PendingVerificationStore + F-11).
4809
4861
  this.pendingVerifications = new PendingVerificationStore('sms');
4810
4862
  this.MAX_ATTEMPTS = 3;
4811
- // Initialize with config
4812
- this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, config);
4863
+ this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, this.options);
4813
4864
  }
4814
4865
  async signIn(options) {
4815
4866
  if (!(options === null || options === void 0 ? void 0 : options.phoneNumber)) {
@@ -5047,14 +5098,9 @@ class SMSProvider {
5047
5098
  // SMS auth is supported if we have the required config
5048
5099
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
5049
5100
  }
5050
- async linkAccount(_options) {
5051
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for SMS authentication');
5052
- }
5053
- async unlinkAccount(_options) {
5054
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for SMS authentication');
5055
- }
5101
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
5056
5102
  async revokeAccess(_token) {
5057
- // SMS auth doesn't have persistent access to revoke
5103
+ // SMS auth doesn't have persistent access to revoke; clear any pending verification.
5058
5104
  this.pendingVerifications.clear();
5059
5105
  }
5060
5106
  }
@@ -5064,20 +5110,23 @@ var smsProvider = /*#__PURE__*/Object.freeze({
5064
5110
  SMSProvider: SMSProvider
5065
5111
  });
5066
5112
 
5067
- class EmailPasswordProvider {
5068
- constructor(config) {
5069
- this.name = 'email-password';
5070
- this.currentUser = null;
5113
+ class EmailPasswordProvider extends BaseAuthProvider {
5114
+ get name() {
5115
+ return 'email-password';
5116
+ }
5117
+ constructor(input) {
5118
+ super(resolveProviderConfig(AuthProvider.EMAIL_PASSWORD, input));
5119
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
5120
+ // so email/password sessions stay in-memory exactly as before (no new storage persistence).
5071
5121
  this.authToken = null;
5072
5122
  this.refreshTokenValue = null;
5073
- // Initialize with config
5074
5123
  this.config = Object.assign({ allowSignUp: true, passwordRequirements: {
5075
5124
  minLength: 8,
5076
5125
  requireUppercase: true,
5077
5126
  requireLowercase: true,
5078
5127
  requireNumbers: true,
5079
5128
  requireSpecialChars: false,
5080
- } }, config);
5129
+ } }, this.options);
5081
5130
  }
5082
5131
  async signIn(options) {
5083
5132
  if (!(options === null || options === void 0 ? void 0 : options.email) || !(options === null || options === void 0 ? void 0 : options.password)) {
@@ -5147,7 +5196,7 @@ class EmailPasswordProvider {
5147
5196
  catch (error) {
5148
5197
  if (error instanceof AuthError)
5149
5198
  throw error;
5150
- throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Failed to sign in with email and password');
5199
+ throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with email and password');
5151
5200
  }
5152
5201
  }
5153
5202
  async signUp(options) {
@@ -5232,7 +5281,7 @@ class EmailPasswordProvider {
5232
5281
  catch (error) {
5233
5282
  if (error instanceof AuthError)
5234
5283
  throw error;
5235
- throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error.message || 'Failed to create account');
5284
+ throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
5236
5285
  }
5237
5286
  }
5238
5287
  async signOut() {
@@ -5298,7 +5347,7 @@ class EmailPasswordProvider {
5298
5347
  catch (error) {
5299
5348
  if (error instanceof AuthError)
5300
5349
  throw error;
5301
- throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Failed to refresh token');
5350
+ throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
5302
5351
  }
5303
5352
  }
5304
5353
  async updatePassword(currentPassword, newPassword) {
@@ -5334,7 +5383,7 @@ class EmailPasswordProvider {
5334
5383
  catch (error) {
5335
5384
  if (error instanceof AuthError)
5336
5385
  throw error;
5337
- throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to update password');
5386
+ throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
5338
5387
  }
5339
5388
  }
5340
5389
  async sendPasswordResetEmail(email) {
@@ -5360,7 +5409,7 @@ class EmailPasswordProvider {
5360
5409
  catch (error) {
5361
5410
  if (error instanceof AuthError)
5362
5411
  throw error;
5363
- throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset email');
5412
+ throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to send password reset email');
5364
5413
  }
5365
5414
  }
5366
5415
  async sendEmailVerification() {
@@ -5389,7 +5438,7 @@ class EmailPasswordProvider {
5389
5438
  catch (error) {
5390
5439
  if (error instanceof AuthError)
5391
5440
  throw error;
5392
- throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error.message || 'Failed to send verification email');
5441
+ throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Failed to send verification email');
5393
5442
  }
5394
5443
  }
5395
5444
  isValidEmail(email) {
@@ -5423,12 +5472,7 @@ class EmailPasswordProvider {
5423
5472
  // Email/Password auth is supported if we have the required config
5424
5473
  return !!this.config.apiUrl;
5425
5474
  }
5426
- async linkAccount(_options) {
5427
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email/password authentication');
5428
- }
5429
- async unlinkAccount(_options) {
5430
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email/password authentication');
5431
- }
5475
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
5432
5476
  async revokeAccess(_token) {
5433
5477
  // For email/password auth, revoking access means signing out
5434
5478
  await this.signOut();
@@ -5440,11 +5484,15 @@ var emailPasswordProvider = /*#__PURE__*/Object.freeze({
5440
5484
  EmailPasswordProvider: EmailPasswordProvider
5441
5485
  });
5442
5486
 
5443
- class BiometricProvider {
5444
- constructor(config = {}) {
5445
- this.name = 'biometric';
5487
+ class BiometricProvider extends BaseAuthProvider {
5488
+ get name() {
5489
+ return 'biometric';
5490
+ }
5491
+ constructor(input = {}) {
5492
+ super(resolveProviderConfig(AuthProvider.BIOMETRIC, input));
5446
5493
  this.biometricAuth = null;
5447
5494
  this.cryptoKeyPromise = null;
5495
+ const config = this.options;
5448
5496
  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);
5449
5497
  this.storageKey =
5450
5498
  config.storageKey || 'capacitor-auth-biometric-credentials';
@@ -5454,7 +5502,9 @@ class BiometricProvider {
5454
5502
  async loadBiometricPlugin() {
5455
5503
  try {
5456
5504
  // Dynamic import to avoid errors if plugin not installed
5457
- const { BiometricAuth } = await import('capacitor-biometric-authentication');
5505
+ const { BiometricAuth } = await import(
5506
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- optional peer dep; module may be absent at build time
5507
+ 'capacitor-biometric-authentication');
5458
5508
  this.biometricAuth = BiometricAuth;
5459
5509
  }
5460
5510
  catch (_a) {
@@ -5462,7 +5512,6 @@ class BiometricProvider {
5462
5512
  }
5463
5513
  }
5464
5514
  async signIn(_options) {
5465
- var _a, _b, _c;
5466
5515
  if (!this.biometricAuth) {
5467
5516
  throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, 'Biometric authentication plugin is not installed. Please install capacitor-biometric-authentication');
5468
5517
  }
@@ -5517,18 +5566,22 @@ class BiometricProvider {
5517
5566
  if (error instanceof AuthError)
5518
5567
  throw error;
5519
5568
  // Handle biometric errors
5520
- if (error.code === 'userCancel' || ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('cancel'))) {
5569
+ const errorCode = typeof error === 'object' && error !== null && 'code' in error
5570
+ ? error.code
5571
+ : undefined;
5572
+ const errorMessage = getErrorMessage(error);
5573
+ if (errorCode === 'userCancel' || (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('cancel'))) {
5521
5574
  throw new AuthError(AuthErrorCode.USER_CANCELLED, 'Authentication cancelled by user');
5522
5575
  }
5523
- else if (error.code === 'biometryLockout' ||
5524
- ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('lockout'))) {
5576
+ else if (errorCode === 'biometryLockout' ||
5577
+ (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('lockout'))) {
5525
5578
  throw new AuthError(AuthErrorCode.BIOMETRIC_LOCKOUT, 'Too many failed attempts. Biometry is locked.');
5526
5579
  }
5527
- else if (error.code === 'biometryNotEnrolled' ||
5528
- ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('enrolled'))) {
5580
+ else if (errorCode === 'biometryNotEnrolled' ||
5581
+ (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('enrolled'))) {
5529
5582
  throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_ENROLLED, 'No biometric credentials are enrolled');
5530
5583
  }
5531
- throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, error.message || 'Biometric authentication failed');
5584
+ throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, errorMessage || 'Biometric authentication failed');
5532
5585
  }
5533
5586
  }
5534
5587
  async signOut() {
@@ -5728,9 +5781,7 @@ class BiometricProvider {
5728
5781
  const result = await this.isAvailable();
5729
5782
  return result.available;
5730
5783
  }
5731
- async linkAccount(_options) {
5732
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for biometric authentication');
5733
- }
5784
+ // linkAccount inherits BaseAuthProvider's OPERATION_NOT_ALLOWED default (F-44).
5734
5785
  async unlinkAccount(_options) {
5735
5786
  // Unlinking biometric auth means clearing stored credentials
5736
5787
  await this.clearStoredCredentials();
@@ -6007,12 +6058,17 @@ var linkedinProvider = /*#__PURE__*/Object.freeze({
6007
6058
  LinkedInProvider: LinkedInProvider
6008
6059
  });
6009
6060
 
6010
- class UsernamePasswordProvider {
6011
- constructor(config) {
6012
- this.name = 'username-password';
6013
- this.currentUser = null;
6061
+ class UsernamePasswordProvider extends BaseAuthProvider {
6062
+ get name() {
6063
+ return 'username-password';
6064
+ }
6065
+ constructor(input) {
6066
+ super(resolveProviderConfig(AuthProvider.USERNAME_PASSWORD, input));
6067
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
6068
+ // so username/password sessions stay in-memory exactly as before (no new storage persistence).
6014
6069
  this.authToken = null;
6015
6070
  this.refreshTokenValue = null;
6071
+ const config = this.options;
6016
6072
  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);
6017
6073
  }
6018
6074
  async signIn(options) {
@@ -6084,7 +6140,7 @@ class UsernamePasswordProvider {
6084
6140
  catch (error) {
6085
6141
  if (error instanceof AuthError)
6086
6142
  throw error;
6087
- throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Failed to sign in with username and password');
6143
+ throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with username and password');
6088
6144
  }
6089
6145
  }
6090
6146
  async signUp(options) {
@@ -6176,7 +6232,7 @@ class UsernamePasswordProvider {
6176
6232
  catch (error) {
6177
6233
  if (error instanceof AuthError)
6178
6234
  throw error;
6179
- throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error.message || 'Failed to create account');
6235
+ throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
6180
6236
  }
6181
6237
  }
6182
6238
  async signOut() {
@@ -6242,7 +6298,7 @@ class UsernamePasswordProvider {
6242
6298
  catch (error) {
6243
6299
  if (error instanceof AuthError)
6244
6300
  throw error;
6245
- throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Failed to refresh token');
6301
+ throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
6246
6302
  }
6247
6303
  }
6248
6304
  async updatePassword(currentPassword, newPassword) {
@@ -6278,7 +6334,7 @@ class UsernamePasswordProvider {
6278
6334
  catch (error) {
6279
6335
  if (error instanceof AuthError)
6280
6336
  throw error;
6281
- throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to update password');
6337
+ throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
6282
6338
  }
6283
6339
  }
6284
6340
  async checkUsernameAvailability(username) {
@@ -6357,12 +6413,7 @@ class UsernamePasswordProvider {
6357
6413
  // Username/Password auth is supported if we have the required config
6358
6414
  return !!this.config.apiUrl;
6359
6415
  }
6360
- async linkAccount(_options) {
6361
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for username/password authentication');
6362
- }
6363
- async unlinkAccount(_options) {
6364
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for username/password authentication');
6365
- }
6416
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6366
6417
  async revokeAccess(_token) {
6367
6418
  // For username/password auth, revoking access means signing out
6368
6419
  await this.signOut();
@@ -6374,15 +6425,18 @@ var usernamePasswordProvider = /*#__PURE__*/Object.freeze({
6374
6425
  UsernamePasswordProvider: UsernamePasswordProvider
6375
6426
  });
6376
6427
 
6377
- class EmailCodeProvider {
6378
- constructor(config) {
6379
- this.name = 'email-code';
6428
+ class EmailCodeProvider extends BaseAuthProvider {
6429
+ get name() {
6430
+ return 'email-code';
6431
+ }
6432
+ constructor(input) {
6433
+ super(resolveProviderConfig(AuthProvider.EMAIL_CODE, input));
6380
6434
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
6381
6435
  // page change between sending and verifying the code. Only non-secret metadata is stored —
6382
6436
  // never the verification code itself (see PendingVerificationStore + F-11).
6383
6437
  this.pendingVerifications = new PendingVerificationStore('email-code');
6384
6438
  this.MAX_ATTEMPTS = 3;
6385
- this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, config);
6439
+ this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, this.options);
6386
6440
  }
6387
6441
  async signIn(options) {
6388
6442
  if (!(options === null || options === void 0 ? void 0 : options.email)) {
@@ -6577,12 +6631,7 @@ class EmailCodeProvider {
6577
6631
  async isSupported() {
6578
6632
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
6579
6633
  }
6580
- async linkAccount(_options) {
6581
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email code authentication');
6582
- }
6583
- async unlinkAccount(_options) {
6584
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email code authentication');
6585
- }
6634
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6586
6635
  async revokeAccess(_token) {
6587
6636
  this.pendingVerifications.clear();
6588
6637
  }
@@ -6627,11 +6676,15 @@ var emailCodeProvider = /*#__PURE__*/Object.freeze({
6627
6676
  EmailCodeProvider: EmailCodeProvider
6628
6677
  });
6629
6678
 
6630
- class PhonePasswordProvider {
6631
- constructor(config) {
6632
- this.name = 'phone-password';
6679
+ class PhonePasswordProvider extends BaseAuthProvider {
6680
+ get name() {
6681
+ return 'phone-password';
6682
+ }
6683
+ constructor(input) {
6684
+ super(resolveProviderConfig(AuthProvider.PHONE_PASSWORD, input));
6633
6685
  this.pendingVerifications = new Map();
6634
- this.currentUser = null;
6686
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
6687
+ // so phone/password sessions stay in-memory exactly as before (no new storage persistence).
6635
6688
  this.storedAccessToken = null;
6636
6689
  this.storedRefreshToken = null;
6637
6690
  this.config = Object.assign({ countryCode: '+1', requirePhoneVerification: false, passwordStrength: {
@@ -6640,7 +6693,7 @@ class PhonePasswordProvider {
6640
6693
  requireLowercase: true,
6641
6694
  requireNumbers: true,
6642
6695
  requireSpecialChars: false,
6643
- } }, config);
6696
+ } }, this.options);
6644
6697
  }
6645
6698
  async signIn(options) {
6646
6699
  const credentials = options === null || options === void 0 ? void 0 : options.credentials;
@@ -6683,12 +6736,12 @@ class PhonePasswordProvider {
6683
6736
  throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
6684
6737
  }
6685
6738
  const data = await response.json();
6686
- return this.createAuthResult(data, phoneNumber);
6739
+ return this.buildAuthResult(data, phoneNumber);
6687
6740
  }
6688
6741
  catch (error) {
6689
6742
  if (error instanceof AuthError)
6690
6743
  throw error;
6691
- throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
6744
+ throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Sign in failed');
6692
6745
  }
6693
6746
  }
6694
6747
  async signUp(phoneNumber, password) {
@@ -6747,12 +6800,12 @@ class PhonePasswordProvider {
6747
6800
  },
6748
6801
  };
6749
6802
  }
6750
- return this.createAuthResult(data, phoneNumber, true);
6803
+ return this.buildAuthResult(data, phoneNumber, true);
6751
6804
  }
6752
6805
  catch (error) {
6753
6806
  if (error instanceof AuthError)
6754
6807
  throw error;
6755
- throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error.message || 'Sign up failed');
6808
+ throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Sign up failed');
6756
6809
  }
6757
6810
  }
6758
6811
  async sendVerificationCode(phoneNumber) {
@@ -6815,12 +6868,12 @@ class PhonePasswordProvider {
6815
6868
  }
6816
6869
  const data = await response.json();
6817
6870
  this.pendingVerifications.delete(phoneNumber);
6818
- return this.createAuthResult(data, phoneNumber);
6871
+ return this.buildAuthResult(data, phoneNumber);
6819
6872
  }
6820
6873
  catch (error) {
6821
6874
  if (error instanceof AuthError)
6822
6875
  throw error;
6823
- throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error.message || 'Phone verification failed');
6876
+ throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Phone verification failed');
6824
6877
  }
6825
6878
  }
6826
6879
  async signOut() {
@@ -6876,7 +6929,7 @@ class PhonePasswordProvider {
6876
6929
  catch (error) {
6877
6930
  if (error instanceof AuthError)
6878
6931
  throw error;
6879
- throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error.message || 'Token refresh failed');
6932
+ throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Token refresh failed');
6880
6933
  }
6881
6934
  }
6882
6935
  async initialize() {
@@ -6885,12 +6938,7 @@ class PhonePasswordProvider {
6885
6938
  async isSupported() {
6886
6939
  return !!(this.config.signInUrl && this.config.signUpUrl);
6887
6940
  }
6888
- async linkAccount(_options) {
6889
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for phone/password authentication');
6890
- }
6891
- async unlinkAccount(_options) {
6892
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for phone/password authentication');
6893
- }
6941
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6894
6942
  async revokeAccess(_token) {
6895
6943
  await this.signOut();
6896
6944
  }
@@ -6917,7 +6965,10 @@ class PhonePasswordProvider {
6917
6965
  throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset');
6918
6966
  }
6919
6967
  }
6920
- createAuthResult(data, phoneNumber, isNewUser = false) {
6968
+ // Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
6969
+ // which has a different signature (this builds a phone-specific result from a backend payload).
6970
+ buildAuthResult(data, phoneNumber, isNewUser = false) {
6971
+ var _a, _b;
6921
6972
  const user = {
6922
6973
  uid: data.uid || this.generateUid(phoneNumber),
6923
6974
  email: data.email || null,
@@ -6941,8 +6992,8 @@ class PhonePasswordProvider {
6941
6992
  },
6942
6993
  };
6943
6994
  this.currentUser = user;
6944
- this.storedAccessToken = data.accessToken;
6945
- this.storedRefreshToken = data.refreshToken;
6995
+ this.storedAccessToken = (_a = data.accessToken) !== null && _a !== void 0 ? _a : null;
6996
+ this.storedRefreshToken = (_b = data.refreshToken) !== null && _b !== void 0 ? _b : null;
6946
6997
  return {
6947
6998
  user,
6948
6999
  credential: {