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.
- package/dist/angular.cjs.js +159 -108
- package/dist/angular.cjs.js.map +1 -1
- package/dist/core.cjs.js +159 -108
- package/dist/core.cjs.js.map +1 -1
- package/dist/esm/angular/auth.module.d.ts +2 -1
- package/dist/esm/angular/auth.module.js.map +1 -1
- package/dist/esm/angular/auth.service.d.ts +5 -5
- package/dist/esm/angular/auth.service.js.map +1 -1
- package/dist/esm/core/auth-manager.js +2 -0
- package/dist/esm/core/auth-manager.js.map +1 -1
- package/dist/esm/core/provider-registry.d.ts +2 -2
- package/dist/esm/core/provider-registry.js +8 -4
- package/dist/esm/core/provider-registry.js.map +1 -1
- package/dist/esm/providers/base-provider.d.ts +11 -0
- package/dist/esm/providers/base-provider.js +30 -3
- package/dist/esm/providers/base-provider.js.map +1 -1
- package/dist/esm/providers/web/biometric-provider.d.ts +7 -8
- package/dist/esm/providers/web/biometric-provider.js +24 -15
- package/dist/esm/providers/web/biometric-provider.js.map +1 -1
- package/dist/esm/providers/web/email-code-provider.d.ts +5 -7
- package/dist/esm/providers/web/email-code-provider.js +10 -11
- package/dist/esm/providers/web/email-code-provider.js.map +1 -1
- package/dist/esm/providers/web/email-password-provider.d.ts +4 -7
- package/dist/esm/providers/web/email-password-provider.js +19 -19
- package/dist/esm/providers/web/email-password-provider.js.map +1 -1
- package/dist/esm/providers/web/magic-link-provider.d.ts +5 -7
- package/dist/esm/providers/web/magic-link-provider.js +12 -13
- package/dist/esm/providers/web/magic-link-provider.js.map +1 -1
- package/dist/esm/providers/web/phone-password-provider.d.ts +5 -8
- package/dist/esm/providers/web/phone-password-provider.js +26 -22
- package/dist/esm/providers/web/phone-password-provider.js.map +1 -1
- package/dist/esm/providers/web/sms-provider.d.ts +5 -7
- package/dist/esm/providers/web/sms-provider.js +11 -13
- package/dist/esm/providers/web/sms-provider.js.map +1 -1
- package/dist/esm/providers/web/username-password-provider.d.ts +4 -7
- package/dist/esm/providers/web/username-password-provider.js +17 -15
- package/dist/esm/providers/web/username-password-provider.js.map +1 -1
- package/dist/esm/utils/error-message.d.ts +8 -0
- package/dist/esm/utils/error-message.js +21 -0
- package/dist/esm/utils/error-message.js.map +1 -0
- package/dist/esm/utils/storage.d.ts +11 -6
- package/dist/esm/utils/storage.js +3 -1
- package/dist/esm/utils/storage.js.map +1 -1
- package/dist/plugin.cjs.js +162 -109
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +162 -109
- package/dist/plugin.js.map +1 -1
- package/dist/react.cjs.js +159 -108
- package/dist/react.cjs.js.map +1 -1
- package/dist/vue.cjs.js +159 -108
- package/dist/vue.cjs.js.map +1 -1
- package/package.json +2 -2
package/dist/vue.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
|
|
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
|
-
|
|
1171
|
-
|
|
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({
|
|
@@ -2124,6 +2150,31 @@ function useAuthConfig() {
|
|
|
2124
2150
|
};
|
|
2125
2151
|
}
|
|
2126
2152
|
|
|
2153
|
+
/**
|
|
2154
|
+
* Normalize a provider constructor argument into a full {@link BaseProviderConfig}.
|
|
2155
|
+
*
|
|
2156
|
+
* The standalone providers are public (exported from `capacitor-auth-manager/providers/web`) and
|
|
2157
|
+
* get constructed two ways: the factory/registry pass a full {@link BaseProviderConfig}, while
|
|
2158
|
+
* tests and direct consumers pass the provider's own bare options object. This helper accepts
|
|
2159
|
+
* either — a bare object is wrapped with an in-memory storage (`AuthPersistence.NONE`, so it never
|
|
2160
|
+
* touches `window` and stays safe under SSR / Node test environments) plus the shared
|
|
2161
|
+
* {@link defaultLogger}. Callers that pass a full config keep their injected storage/logger.
|
|
2162
|
+
*/
|
|
2163
|
+
function resolveProviderConfig(provider, input) {
|
|
2164
|
+
if (typeof input === 'object' &&
|
|
2165
|
+
input !== null &&
|
|
2166
|
+
'storage' in input &&
|
|
2167
|
+
'logger' in input &&
|
|
2168
|
+
'options' in input) {
|
|
2169
|
+
return input;
|
|
2170
|
+
}
|
|
2171
|
+
return {
|
|
2172
|
+
provider,
|
|
2173
|
+
options: (input !== null && input !== void 0 ? input : {}),
|
|
2174
|
+
storage: new WebStorage(AuthPersistence.NONE),
|
|
2175
|
+
logger: defaultLogger,
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2127
2178
|
class BaseAuthProvider {
|
|
2128
2179
|
get name() {
|
|
2129
2180
|
return this.provider;
|
|
@@ -2143,13 +2194,13 @@ class BaseAuthProvider {
|
|
|
2143
2194
|
// across every provider (see AuthProviderInterface, where they are optional). Marking them
|
|
2144
2195
|
// abstract previously forced every subclass to re-implement them just to throw.
|
|
2145
2196
|
async linkAccount(_options) {
|
|
2146
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `
|
|
2197
|
+
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account linking is not supported by provider ${this.provider}`, this.provider);
|
|
2147
2198
|
}
|
|
2148
2199
|
async unlinkAccount(_options) {
|
|
2149
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `
|
|
2200
|
+
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account unlinking is not supported by provider ${this.provider}`, this.provider);
|
|
2150
2201
|
}
|
|
2151
2202
|
async revokeAccess(_token) {
|
|
2152
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `
|
|
2203
|
+
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Access revocation is not supported by provider ${this.provider}`, this.provider);
|
|
2153
2204
|
}
|
|
2154
2205
|
async getCurrentUser() {
|
|
2155
2206
|
if (!this.isInitialized) {
|
|
@@ -4464,16 +4515,19 @@ class PendingVerificationStore {
|
|
|
4464
4515
|
}
|
|
4465
4516
|
}
|
|
4466
4517
|
|
|
4467
|
-
class MagicLinkProvider {
|
|
4468
|
-
|
|
4469
|
-
|
|
4518
|
+
class MagicLinkProvider extends BaseAuthProvider {
|
|
4519
|
+
get name() {
|
|
4520
|
+
return 'magic-link';
|
|
4521
|
+
}
|
|
4522
|
+
constructor(input) {
|
|
4523
|
+
super(resolveProviderConfig(AuthProvider.EMAIL_MAGIC_LINK, input));
|
|
4470
4524
|
// Persisted (SSR-guarded localStorage) so a magic link clicked from an email — which opens a
|
|
4471
4525
|
// FRESH page load with empty in-memory state — can still find its pending entry to verify
|
|
4472
4526
|
// against. Keyed by the link token (already present in the callback URL); we store only the
|
|
4473
4527
|
// email + expiry, never any additional secret (see PendingVerificationStore + F-11).
|
|
4474
4528
|
this.pendingVerification = new PendingVerificationStore('magic-link');
|
|
4475
|
-
//
|
|
4476
|
-
this.config =
|
|
4529
|
+
// Magic link uses its config as-is (no defaults to merge).
|
|
4530
|
+
this.config = this.options;
|
|
4477
4531
|
// Check for magic link callback on initialization
|
|
4478
4532
|
this.checkForMagicLinkCallback();
|
|
4479
4533
|
}
|
|
@@ -4723,14 +4777,9 @@ class MagicLinkProvider {
|
|
|
4723
4777
|
// Magic link auth is supported if we have the required config
|
|
4724
4778
|
return !!this.config.sendLinkUrl;
|
|
4725
4779
|
}
|
|
4726
|
-
|
|
4727
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for magic link authentication');
|
|
4728
|
-
}
|
|
4729
|
-
async unlinkAccount(_options) {
|
|
4730
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for magic link authentication');
|
|
4731
|
-
}
|
|
4780
|
+
// linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
|
|
4732
4781
|
async revokeAccess(_token) {
|
|
4733
|
-
// Magic link doesn't have persistent access to revoke
|
|
4782
|
+
// Magic link doesn't have persistent access to revoke; clear any pending verification.
|
|
4734
4783
|
this.pendingVerification.clear();
|
|
4735
4784
|
}
|
|
4736
4785
|
}
|
|
@@ -4740,16 +4789,18 @@ var magicLinkProvider = /*#__PURE__*/Object.freeze({
|
|
|
4740
4789
|
MagicLinkProvider: MagicLinkProvider
|
|
4741
4790
|
});
|
|
4742
4791
|
|
|
4743
|
-
class SMSProvider {
|
|
4744
|
-
|
|
4745
|
-
|
|
4792
|
+
class SMSProvider extends BaseAuthProvider {
|
|
4793
|
+
get name() {
|
|
4794
|
+
return 'sms';
|
|
4795
|
+
}
|
|
4796
|
+
constructor(input) {
|
|
4797
|
+
super(resolveProviderConfig(AuthProvider.SMS, input));
|
|
4746
4798
|
// Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
|
|
4747
4799
|
// page change between sending and verifying the code. Only non-secret metadata is stored —
|
|
4748
4800
|
// never the SMS code itself (see PendingVerificationStore + F-11).
|
|
4749
4801
|
this.pendingVerifications = new PendingVerificationStore('sms');
|
|
4750
4802
|
this.MAX_ATTEMPTS = 3;
|
|
4751
|
-
|
|
4752
|
-
this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, config);
|
|
4803
|
+
this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, this.options);
|
|
4753
4804
|
}
|
|
4754
4805
|
async signIn(options) {
|
|
4755
4806
|
if (!(options === null || options === void 0 ? void 0 : options.phoneNumber)) {
|
|
@@ -4987,14 +5038,9 @@ class SMSProvider {
|
|
|
4987
5038
|
// SMS auth is supported if we have the required config
|
|
4988
5039
|
return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
|
|
4989
5040
|
}
|
|
4990
|
-
|
|
4991
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for SMS authentication');
|
|
4992
|
-
}
|
|
4993
|
-
async unlinkAccount(_options) {
|
|
4994
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for SMS authentication');
|
|
4995
|
-
}
|
|
5041
|
+
// linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
|
|
4996
5042
|
async revokeAccess(_token) {
|
|
4997
|
-
// SMS auth doesn't have persistent access to revoke
|
|
5043
|
+
// SMS auth doesn't have persistent access to revoke; clear any pending verification.
|
|
4998
5044
|
this.pendingVerifications.clear();
|
|
4999
5045
|
}
|
|
5000
5046
|
}
|
|
@@ -5004,20 +5050,23 @@ var smsProvider = /*#__PURE__*/Object.freeze({
|
|
|
5004
5050
|
SMSProvider: SMSProvider
|
|
5005
5051
|
});
|
|
5006
5052
|
|
|
5007
|
-
class EmailPasswordProvider {
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5053
|
+
class EmailPasswordProvider extends BaseAuthProvider {
|
|
5054
|
+
get name() {
|
|
5055
|
+
return 'email-password';
|
|
5056
|
+
}
|
|
5057
|
+
constructor(input) {
|
|
5058
|
+
super(resolveProviderConfig(AuthProvider.EMAIL_PASSWORD, input));
|
|
5059
|
+
// currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
|
|
5060
|
+
// so email/password sessions stay in-memory exactly as before (no new storage persistence).
|
|
5011
5061
|
this.authToken = null;
|
|
5012
5062
|
this.refreshTokenValue = null;
|
|
5013
|
-
// Initialize with config
|
|
5014
5063
|
this.config = Object.assign({ allowSignUp: true, passwordRequirements: {
|
|
5015
5064
|
minLength: 8,
|
|
5016
5065
|
requireUppercase: true,
|
|
5017
5066
|
requireLowercase: true,
|
|
5018
5067
|
requireNumbers: true,
|
|
5019
5068
|
requireSpecialChars: false,
|
|
5020
|
-
} },
|
|
5069
|
+
} }, this.options);
|
|
5021
5070
|
}
|
|
5022
5071
|
async signIn(options) {
|
|
5023
5072
|
if (!(options === null || options === void 0 ? void 0 : options.email) || !(options === null || options === void 0 ? void 0 : options.password)) {
|
|
@@ -5087,7 +5136,7 @@ class EmailPasswordProvider {
|
|
|
5087
5136
|
catch (error) {
|
|
5088
5137
|
if (error instanceof AuthError)
|
|
5089
5138
|
throw error;
|
|
5090
|
-
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error
|
|
5139
|
+
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with email and password');
|
|
5091
5140
|
}
|
|
5092
5141
|
}
|
|
5093
5142
|
async signUp(options) {
|
|
@@ -5172,7 +5221,7 @@ class EmailPasswordProvider {
|
|
|
5172
5221
|
catch (error) {
|
|
5173
5222
|
if (error instanceof AuthError)
|
|
5174
5223
|
throw error;
|
|
5175
|
-
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error
|
|
5224
|
+
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
|
|
5176
5225
|
}
|
|
5177
5226
|
}
|
|
5178
5227
|
async signOut() {
|
|
@@ -5238,7 +5287,7 @@ class EmailPasswordProvider {
|
|
|
5238
5287
|
catch (error) {
|
|
5239
5288
|
if (error instanceof AuthError)
|
|
5240
5289
|
throw error;
|
|
5241
|
-
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
5290
|
+
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
|
|
5242
5291
|
}
|
|
5243
5292
|
}
|
|
5244
5293
|
async updatePassword(currentPassword, newPassword) {
|
|
@@ -5274,7 +5323,7 @@ class EmailPasswordProvider {
|
|
|
5274
5323
|
catch (error) {
|
|
5275
5324
|
if (error instanceof AuthError)
|
|
5276
5325
|
throw error;
|
|
5277
|
-
throw new AuthError(AuthErrorCode.SERVER_ERROR, error
|
|
5326
|
+
throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
|
|
5278
5327
|
}
|
|
5279
5328
|
}
|
|
5280
5329
|
async sendPasswordResetEmail(email) {
|
|
@@ -5300,7 +5349,7 @@ class EmailPasswordProvider {
|
|
|
5300
5349
|
catch (error) {
|
|
5301
5350
|
if (error instanceof AuthError)
|
|
5302
5351
|
throw error;
|
|
5303
|
-
throw new AuthError(AuthErrorCode.SERVER_ERROR, error
|
|
5352
|
+
throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to send password reset email');
|
|
5304
5353
|
}
|
|
5305
5354
|
}
|
|
5306
5355
|
async sendEmailVerification() {
|
|
@@ -5329,7 +5378,7 @@ class EmailPasswordProvider {
|
|
|
5329
5378
|
catch (error) {
|
|
5330
5379
|
if (error instanceof AuthError)
|
|
5331
5380
|
throw error;
|
|
5332
|
-
throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error
|
|
5381
|
+
throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Failed to send verification email');
|
|
5333
5382
|
}
|
|
5334
5383
|
}
|
|
5335
5384
|
isValidEmail(email) {
|
|
@@ -5363,12 +5412,7 @@ class EmailPasswordProvider {
|
|
|
5363
5412
|
// Email/Password auth is supported if we have the required config
|
|
5364
5413
|
return !!this.config.apiUrl;
|
|
5365
5414
|
}
|
|
5366
|
-
|
|
5367
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email/password authentication');
|
|
5368
|
-
}
|
|
5369
|
-
async unlinkAccount(_options) {
|
|
5370
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email/password authentication');
|
|
5371
|
-
}
|
|
5415
|
+
// linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
|
|
5372
5416
|
async revokeAccess(_token) {
|
|
5373
5417
|
// For email/password auth, revoking access means signing out
|
|
5374
5418
|
await this.signOut();
|
|
@@ -5380,11 +5424,15 @@ var emailPasswordProvider = /*#__PURE__*/Object.freeze({
|
|
|
5380
5424
|
EmailPasswordProvider: EmailPasswordProvider
|
|
5381
5425
|
});
|
|
5382
5426
|
|
|
5383
|
-
class BiometricProvider {
|
|
5384
|
-
|
|
5385
|
-
|
|
5427
|
+
class BiometricProvider extends BaseAuthProvider {
|
|
5428
|
+
get name() {
|
|
5429
|
+
return 'biometric';
|
|
5430
|
+
}
|
|
5431
|
+
constructor(input = {}) {
|
|
5432
|
+
super(resolveProviderConfig(AuthProvider.BIOMETRIC, input));
|
|
5386
5433
|
this.biometricAuth = null;
|
|
5387
5434
|
this.cryptoKeyPromise = null;
|
|
5435
|
+
const config = this.options;
|
|
5388
5436
|
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);
|
|
5389
5437
|
this.storageKey =
|
|
5390
5438
|
config.storageKey || 'capacitor-auth-biometric-credentials';
|
|
@@ -5394,7 +5442,9 @@ class BiometricProvider {
|
|
|
5394
5442
|
async loadBiometricPlugin() {
|
|
5395
5443
|
try {
|
|
5396
5444
|
// Dynamic import to avoid errors if plugin not installed
|
|
5397
|
-
const { BiometricAuth } = await import(
|
|
5445
|
+
const { BiometricAuth } = await import(
|
|
5446
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- optional peer dep; module may be absent at build time
|
|
5447
|
+
'capacitor-biometric-authentication');
|
|
5398
5448
|
this.biometricAuth = BiometricAuth;
|
|
5399
5449
|
}
|
|
5400
5450
|
catch (_a) {
|
|
@@ -5402,7 +5452,6 @@ class BiometricProvider {
|
|
|
5402
5452
|
}
|
|
5403
5453
|
}
|
|
5404
5454
|
async signIn(_options) {
|
|
5405
|
-
var _a, _b, _c;
|
|
5406
5455
|
if (!this.biometricAuth) {
|
|
5407
5456
|
throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, 'Biometric authentication plugin is not installed. Please install capacitor-biometric-authentication');
|
|
5408
5457
|
}
|
|
@@ -5457,18 +5506,22 @@ class BiometricProvider {
|
|
|
5457
5506
|
if (error instanceof AuthError)
|
|
5458
5507
|
throw error;
|
|
5459
5508
|
// Handle biometric errors
|
|
5460
|
-
|
|
5509
|
+
const errorCode = typeof error === 'object' && error !== null && 'code' in error
|
|
5510
|
+
? error.code
|
|
5511
|
+
: undefined;
|
|
5512
|
+
const errorMessage = getErrorMessage(error);
|
|
5513
|
+
if (errorCode === 'userCancel' || (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('cancel'))) {
|
|
5461
5514
|
throw new AuthError(AuthErrorCode.USER_CANCELLED, 'Authentication cancelled by user');
|
|
5462
5515
|
}
|
|
5463
|
-
else if (
|
|
5464
|
-
(
|
|
5516
|
+
else if (errorCode === 'biometryLockout' ||
|
|
5517
|
+
(errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('lockout'))) {
|
|
5465
5518
|
throw new AuthError(AuthErrorCode.BIOMETRIC_LOCKOUT, 'Too many failed attempts. Biometry is locked.');
|
|
5466
5519
|
}
|
|
5467
|
-
else if (
|
|
5468
|
-
(
|
|
5520
|
+
else if (errorCode === 'biometryNotEnrolled' ||
|
|
5521
|
+
(errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('enrolled'))) {
|
|
5469
5522
|
throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_ENROLLED, 'No biometric credentials are enrolled');
|
|
5470
5523
|
}
|
|
5471
|
-
throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED,
|
|
5524
|
+
throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, errorMessage || 'Biometric authentication failed');
|
|
5472
5525
|
}
|
|
5473
5526
|
}
|
|
5474
5527
|
async signOut() {
|
|
@@ -5668,9 +5721,7 @@ class BiometricProvider {
|
|
|
5668
5721
|
const result = await this.isAvailable();
|
|
5669
5722
|
return result.available;
|
|
5670
5723
|
}
|
|
5671
|
-
|
|
5672
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for biometric authentication');
|
|
5673
|
-
}
|
|
5724
|
+
// linkAccount inherits BaseAuthProvider's OPERATION_NOT_ALLOWED default (F-44).
|
|
5674
5725
|
async unlinkAccount(_options) {
|
|
5675
5726
|
// Unlinking biometric auth means clearing stored credentials
|
|
5676
5727
|
await this.clearStoredCredentials();
|
|
@@ -5947,12 +5998,17 @@ var linkedinProvider = /*#__PURE__*/Object.freeze({
|
|
|
5947
5998
|
LinkedInProvider: LinkedInProvider
|
|
5948
5999
|
});
|
|
5949
6000
|
|
|
5950
|
-
class UsernamePasswordProvider {
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
6001
|
+
class UsernamePasswordProvider extends BaseAuthProvider {
|
|
6002
|
+
get name() {
|
|
6003
|
+
return 'username-password';
|
|
6004
|
+
}
|
|
6005
|
+
constructor(input) {
|
|
6006
|
+
super(resolveProviderConfig(AuthProvider.USERNAME_PASSWORD, input));
|
|
6007
|
+
// currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
|
|
6008
|
+
// so username/password sessions stay in-memory exactly as before (no new storage persistence).
|
|
5954
6009
|
this.authToken = null;
|
|
5955
6010
|
this.refreshTokenValue = null;
|
|
6011
|
+
const config = this.options;
|
|
5956
6012
|
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);
|
|
5957
6013
|
}
|
|
5958
6014
|
async signIn(options) {
|
|
@@ -6024,7 +6080,7 @@ class UsernamePasswordProvider {
|
|
|
6024
6080
|
catch (error) {
|
|
6025
6081
|
if (error instanceof AuthError)
|
|
6026
6082
|
throw error;
|
|
6027
|
-
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error
|
|
6083
|
+
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with username and password');
|
|
6028
6084
|
}
|
|
6029
6085
|
}
|
|
6030
6086
|
async signUp(options) {
|
|
@@ -6116,7 +6172,7 @@ class UsernamePasswordProvider {
|
|
|
6116
6172
|
catch (error) {
|
|
6117
6173
|
if (error instanceof AuthError)
|
|
6118
6174
|
throw error;
|
|
6119
|
-
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error
|
|
6175
|
+
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
|
|
6120
6176
|
}
|
|
6121
6177
|
}
|
|
6122
6178
|
async signOut() {
|
|
@@ -6182,7 +6238,7 @@ class UsernamePasswordProvider {
|
|
|
6182
6238
|
catch (error) {
|
|
6183
6239
|
if (error instanceof AuthError)
|
|
6184
6240
|
throw error;
|
|
6185
|
-
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
6241
|
+
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
|
|
6186
6242
|
}
|
|
6187
6243
|
}
|
|
6188
6244
|
async updatePassword(currentPassword, newPassword) {
|
|
@@ -6218,7 +6274,7 @@ class UsernamePasswordProvider {
|
|
|
6218
6274
|
catch (error) {
|
|
6219
6275
|
if (error instanceof AuthError)
|
|
6220
6276
|
throw error;
|
|
6221
|
-
throw new AuthError(AuthErrorCode.SERVER_ERROR, error
|
|
6277
|
+
throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
|
|
6222
6278
|
}
|
|
6223
6279
|
}
|
|
6224
6280
|
async checkUsernameAvailability(username) {
|
|
@@ -6297,12 +6353,7 @@ class UsernamePasswordProvider {
|
|
|
6297
6353
|
// Username/Password auth is supported if we have the required config
|
|
6298
6354
|
return !!this.config.apiUrl;
|
|
6299
6355
|
}
|
|
6300
|
-
|
|
6301
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for username/password authentication');
|
|
6302
|
-
}
|
|
6303
|
-
async unlinkAccount(_options) {
|
|
6304
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for username/password authentication');
|
|
6305
|
-
}
|
|
6356
|
+
// linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
|
|
6306
6357
|
async revokeAccess(_token) {
|
|
6307
6358
|
// For username/password auth, revoking access means signing out
|
|
6308
6359
|
await this.signOut();
|
|
@@ -6314,15 +6365,18 @@ var usernamePasswordProvider = /*#__PURE__*/Object.freeze({
|
|
|
6314
6365
|
UsernamePasswordProvider: UsernamePasswordProvider
|
|
6315
6366
|
});
|
|
6316
6367
|
|
|
6317
|
-
class EmailCodeProvider {
|
|
6318
|
-
|
|
6319
|
-
|
|
6368
|
+
class EmailCodeProvider extends BaseAuthProvider {
|
|
6369
|
+
get name() {
|
|
6370
|
+
return 'email-code';
|
|
6371
|
+
}
|
|
6372
|
+
constructor(input) {
|
|
6373
|
+
super(resolveProviderConfig(AuthProvider.EMAIL_CODE, input));
|
|
6320
6374
|
// Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
|
|
6321
6375
|
// page change between sending and verifying the code. Only non-secret metadata is stored —
|
|
6322
6376
|
// never the verification code itself (see PendingVerificationStore + F-11).
|
|
6323
6377
|
this.pendingVerifications = new PendingVerificationStore('email-code');
|
|
6324
6378
|
this.MAX_ATTEMPTS = 3;
|
|
6325
|
-
this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 },
|
|
6379
|
+
this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, this.options);
|
|
6326
6380
|
}
|
|
6327
6381
|
async signIn(options) {
|
|
6328
6382
|
if (!(options === null || options === void 0 ? void 0 : options.email)) {
|
|
@@ -6517,12 +6571,7 @@ class EmailCodeProvider {
|
|
|
6517
6571
|
async isSupported() {
|
|
6518
6572
|
return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
|
|
6519
6573
|
}
|
|
6520
|
-
|
|
6521
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email code authentication');
|
|
6522
|
-
}
|
|
6523
|
-
async unlinkAccount(_options) {
|
|
6524
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email code authentication');
|
|
6525
|
-
}
|
|
6574
|
+
// linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
|
|
6526
6575
|
async revokeAccess(_token) {
|
|
6527
6576
|
this.pendingVerifications.clear();
|
|
6528
6577
|
}
|
|
@@ -6567,11 +6616,15 @@ var emailCodeProvider = /*#__PURE__*/Object.freeze({
|
|
|
6567
6616
|
EmailCodeProvider: EmailCodeProvider
|
|
6568
6617
|
});
|
|
6569
6618
|
|
|
6570
|
-
class PhonePasswordProvider {
|
|
6571
|
-
|
|
6572
|
-
|
|
6619
|
+
class PhonePasswordProvider extends BaseAuthProvider {
|
|
6620
|
+
get name() {
|
|
6621
|
+
return 'phone-password';
|
|
6622
|
+
}
|
|
6623
|
+
constructor(input) {
|
|
6624
|
+
super(resolveProviderConfig(AuthProvider.PHONE_PASSWORD, input));
|
|
6573
6625
|
this.pendingVerifications = new Map();
|
|
6574
|
-
|
|
6626
|
+
// currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
|
|
6627
|
+
// so phone/password sessions stay in-memory exactly as before (no new storage persistence).
|
|
6575
6628
|
this.storedAccessToken = null;
|
|
6576
6629
|
this.storedRefreshToken = null;
|
|
6577
6630
|
this.config = Object.assign({ countryCode: '+1', requirePhoneVerification: false, passwordStrength: {
|
|
@@ -6580,7 +6633,7 @@ class PhonePasswordProvider {
|
|
|
6580
6633
|
requireLowercase: true,
|
|
6581
6634
|
requireNumbers: true,
|
|
6582
6635
|
requireSpecialChars: false,
|
|
6583
|
-
} },
|
|
6636
|
+
} }, this.options);
|
|
6584
6637
|
}
|
|
6585
6638
|
async signIn(options) {
|
|
6586
6639
|
const credentials = options === null || options === void 0 ? void 0 : options.credentials;
|
|
@@ -6623,12 +6676,12 @@ class PhonePasswordProvider {
|
|
|
6623
6676
|
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
|
|
6624
6677
|
}
|
|
6625
6678
|
const data = await response.json();
|
|
6626
|
-
return this.
|
|
6679
|
+
return this.buildAuthResult(data, phoneNumber);
|
|
6627
6680
|
}
|
|
6628
6681
|
catch (error) {
|
|
6629
6682
|
if (error instanceof AuthError)
|
|
6630
6683
|
throw error;
|
|
6631
|
-
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error
|
|
6684
|
+
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Sign in failed');
|
|
6632
6685
|
}
|
|
6633
6686
|
}
|
|
6634
6687
|
async signUp(phoneNumber, password) {
|
|
@@ -6687,12 +6740,12 @@ class PhonePasswordProvider {
|
|
|
6687
6740
|
},
|
|
6688
6741
|
};
|
|
6689
6742
|
}
|
|
6690
|
-
return this.
|
|
6743
|
+
return this.buildAuthResult(data, phoneNumber, true);
|
|
6691
6744
|
}
|
|
6692
6745
|
catch (error) {
|
|
6693
6746
|
if (error instanceof AuthError)
|
|
6694
6747
|
throw error;
|
|
6695
|
-
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error
|
|
6748
|
+
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Sign up failed');
|
|
6696
6749
|
}
|
|
6697
6750
|
}
|
|
6698
6751
|
async sendVerificationCode(phoneNumber) {
|
|
@@ -6755,12 +6808,12 @@ class PhonePasswordProvider {
|
|
|
6755
6808
|
}
|
|
6756
6809
|
const data = await response.json();
|
|
6757
6810
|
this.pendingVerifications.delete(phoneNumber);
|
|
6758
|
-
return this.
|
|
6811
|
+
return this.buildAuthResult(data, phoneNumber);
|
|
6759
6812
|
}
|
|
6760
6813
|
catch (error) {
|
|
6761
6814
|
if (error instanceof AuthError)
|
|
6762
6815
|
throw error;
|
|
6763
|
-
throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error
|
|
6816
|
+
throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Phone verification failed');
|
|
6764
6817
|
}
|
|
6765
6818
|
}
|
|
6766
6819
|
async signOut() {
|
|
@@ -6816,7 +6869,7 @@ class PhonePasswordProvider {
|
|
|
6816
6869
|
catch (error) {
|
|
6817
6870
|
if (error instanceof AuthError)
|
|
6818
6871
|
throw error;
|
|
6819
|
-
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
6872
|
+
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Token refresh failed');
|
|
6820
6873
|
}
|
|
6821
6874
|
}
|
|
6822
6875
|
async initialize() {
|
|
@@ -6825,12 +6878,7 @@ class PhonePasswordProvider {
|
|
|
6825
6878
|
async isSupported() {
|
|
6826
6879
|
return !!(this.config.signInUrl && this.config.signUpUrl);
|
|
6827
6880
|
}
|
|
6828
|
-
|
|
6829
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for phone/password authentication');
|
|
6830
|
-
}
|
|
6831
|
-
async unlinkAccount(_options) {
|
|
6832
|
-
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for phone/password authentication');
|
|
6833
|
-
}
|
|
6881
|
+
// linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
|
|
6834
6882
|
async revokeAccess(_token) {
|
|
6835
6883
|
await this.signOut();
|
|
6836
6884
|
}
|
|
@@ -6857,7 +6905,10 @@ class PhonePasswordProvider {
|
|
|
6857
6905
|
throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset');
|
|
6858
6906
|
}
|
|
6859
6907
|
}
|
|
6860
|
-
createAuthResult
|
|
6908
|
+
// Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
|
|
6909
|
+
// which has a different signature (this builds a phone-specific result from a backend payload).
|
|
6910
|
+
buildAuthResult(data, phoneNumber, isNewUser = false) {
|
|
6911
|
+
var _a, _b;
|
|
6861
6912
|
const user = {
|
|
6862
6913
|
uid: data.uid || this.generateUid(phoneNumber),
|
|
6863
6914
|
email: data.email || null,
|
|
@@ -6881,8 +6932,8 @@ class PhonePasswordProvider {
|
|
|
6881
6932
|
},
|
|
6882
6933
|
};
|
|
6883
6934
|
this.currentUser = user;
|
|
6884
|
-
this.storedAccessToken = data.accessToken;
|
|
6885
|
-
this.storedRefreshToken = data.refreshToken;
|
|
6935
|
+
this.storedAccessToken = (_a = data.accessToken) !== null && _a !== void 0 ? _a : null;
|
|
6936
|
+
this.storedRefreshToken = (_b = data.refreshToken) !== null && _b !== void 0 ? _b : null;
|
|
6886
6937
|
return {
|
|
6887
6938
|
user,
|
|
6888
6939
|
credential: {
|