capacitor-auth-manager 2.3.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 +60 -28
- package/dist/angular.cjs.js.map +1 -1
- package/dist/core.cjs.js +60 -28
- 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.js.map +1 -1
- package/dist/esm/providers/web/biometric-provider.d.ts +2 -2
- package/dist/esm/providers/web/biometric-provider.js +14 -8
- package/dist/esm/providers/web/biometric-provider.js.map +1 -1
- package/dist/esm/providers/web/email-password-provider.js +7 -6
- package/dist/esm/providers/web/email-password-provider.js.map +1 -1
- package/dist/esm/providers/web/phone-password-provider.js +8 -6
- package/dist/esm/providers/web/phone-password-provider.js.map +1 -1
- package/dist/esm/providers/web/username-password-provider.js +5 -4
- 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 +63 -29
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +63 -29
- package/dist/plugin.js.map +1 -1
- package/dist/react.cjs.js +60 -28
- package/dist/react.cjs.js.map +1 -1
- package/dist/vue.cjs.js +60 -28
- package/dist/vue.cjs.js.map +1 -1
- package/package.json +1 -1
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({
|
|
@@ -5110,7 +5136,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
|
|
|
5110
5136
|
catch (error) {
|
|
5111
5137
|
if (error instanceof AuthError)
|
|
5112
5138
|
throw error;
|
|
5113
|
-
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');
|
|
5114
5140
|
}
|
|
5115
5141
|
}
|
|
5116
5142
|
async signUp(options) {
|
|
@@ -5195,7 +5221,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
|
|
|
5195
5221
|
catch (error) {
|
|
5196
5222
|
if (error instanceof AuthError)
|
|
5197
5223
|
throw error;
|
|
5198
|
-
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error
|
|
5224
|
+
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
|
|
5199
5225
|
}
|
|
5200
5226
|
}
|
|
5201
5227
|
async signOut() {
|
|
@@ -5261,7 +5287,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
|
|
|
5261
5287
|
catch (error) {
|
|
5262
5288
|
if (error instanceof AuthError)
|
|
5263
5289
|
throw error;
|
|
5264
|
-
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
5290
|
+
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
|
|
5265
5291
|
}
|
|
5266
5292
|
}
|
|
5267
5293
|
async updatePassword(currentPassword, newPassword) {
|
|
@@ -5297,7 +5323,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
|
|
|
5297
5323
|
catch (error) {
|
|
5298
5324
|
if (error instanceof AuthError)
|
|
5299
5325
|
throw error;
|
|
5300
|
-
throw new AuthError(AuthErrorCode.SERVER_ERROR, error
|
|
5326
|
+
throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
|
|
5301
5327
|
}
|
|
5302
5328
|
}
|
|
5303
5329
|
async sendPasswordResetEmail(email) {
|
|
@@ -5323,7 +5349,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
|
|
|
5323
5349
|
catch (error) {
|
|
5324
5350
|
if (error instanceof AuthError)
|
|
5325
5351
|
throw error;
|
|
5326
|
-
throw new AuthError(AuthErrorCode.SERVER_ERROR, error
|
|
5352
|
+
throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to send password reset email');
|
|
5327
5353
|
}
|
|
5328
5354
|
}
|
|
5329
5355
|
async sendEmailVerification() {
|
|
@@ -5352,7 +5378,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
|
|
|
5352
5378
|
catch (error) {
|
|
5353
5379
|
if (error instanceof AuthError)
|
|
5354
5380
|
throw error;
|
|
5355
|
-
throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error
|
|
5381
|
+
throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Failed to send verification email');
|
|
5356
5382
|
}
|
|
5357
5383
|
}
|
|
5358
5384
|
isValidEmail(email) {
|
|
@@ -5416,7 +5442,9 @@ class BiometricProvider extends BaseAuthProvider {
|
|
|
5416
5442
|
async loadBiometricPlugin() {
|
|
5417
5443
|
try {
|
|
5418
5444
|
// Dynamic import to avoid errors if plugin not installed
|
|
5419
|
-
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');
|
|
5420
5448
|
this.biometricAuth = BiometricAuth;
|
|
5421
5449
|
}
|
|
5422
5450
|
catch (_a) {
|
|
@@ -5424,7 +5452,6 @@ class BiometricProvider extends BaseAuthProvider {
|
|
|
5424
5452
|
}
|
|
5425
5453
|
}
|
|
5426
5454
|
async signIn(_options) {
|
|
5427
|
-
var _a, _b, _c;
|
|
5428
5455
|
if (!this.biometricAuth) {
|
|
5429
5456
|
throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, 'Biometric authentication plugin is not installed. Please install capacitor-biometric-authentication');
|
|
5430
5457
|
}
|
|
@@ -5479,18 +5506,22 @@ class BiometricProvider extends BaseAuthProvider {
|
|
|
5479
5506
|
if (error instanceof AuthError)
|
|
5480
5507
|
throw error;
|
|
5481
5508
|
// Handle biometric errors
|
|
5482
|
-
|
|
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'))) {
|
|
5483
5514
|
throw new AuthError(AuthErrorCode.USER_CANCELLED, 'Authentication cancelled by user');
|
|
5484
5515
|
}
|
|
5485
|
-
else if (
|
|
5486
|
-
(
|
|
5516
|
+
else if (errorCode === 'biometryLockout' ||
|
|
5517
|
+
(errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('lockout'))) {
|
|
5487
5518
|
throw new AuthError(AuthErrorCode.BIOMETRIC_LOCKOUT, 'Too many failed attempts. Biometry is locked.');
|
|
5488
5519
|
}
|
|
5489
|
-
else if (
|
|
5490
|
-
(
|
|
5520
|
+
else if (errorCode === 'biometryNotEnrolled' ||
|
|
5521
|
+
(errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('enrolled'))) {
|
|
5491
5522
|
throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_ENROLLED, 'No biometric credentials are enrolled');
|
|
5492
5523
|
}
|
|
5493
|
-
throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED,
|
|
5524
|
+
throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, errorMessage || 'Biometric authentication failed');
|
|
5494
5525
|
}
|
|
5495
5526
|
}
|
|
5496
5527
|
async signOut() {
|
|
@@ -6049,7 +6080,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
|
|
|
6049
6080
|
catch (error) {
|
|
6050
6081
|
if (error instanceof AuthError)
|
|
6051
6082
|
throw error;
|
|
6052
|
-
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');
|
|
6053
6084
|
}
|
|
6054
6085
|
}
|
|
6055
6086
|
async signUp(options) {
|
|
@@ -6141,7 +6172,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
|
|
|
6141
6172
|
catch (error) {
|
|
6142
6173
|
if (error instanceof AuthError)
|
|
6143
6174
|
throw error;
|
|
6144
|
-
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error
|
|
6175
|
+
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
|
|
6145
6176
|
}
|
|
6146
6177
|
}
|
|
6147
6178
|
async signOut() {
|
|
@@ -6207,7 +6238,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
|
|
|
6207
6238
|
catch (error) {
|
|
6208
6239
|
if (error instanceof AuthError)
|
|
6209
6240
|
throw error;
|
|
6210
|
-
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
6241
|
+
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
|
|
6211
6242
|
}
|
|
6212
6243
|
}
|
|
6213
6244
|
async updatePassword(currentPassword, newPassword) {
|
|
@@ -6243,7 +6274,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
|
|
|
6243
6274
|
catch (error) {
|
|
6244
6275
|
if (error instanceof AuthError)
|
|
6245
6276
|
throw error;
|
|
6246
|
-
throw new AuthError(AuthErrorCode.SERVER_ERROR, error
|
|
6277
|
+
throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
|
|
6247
6278
|
}
|
|
6248
6279
|
}
|
|
6249
6280
|
async checkUsernameAvailability(username) {
|
|
@@ -6650,7 +6681,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
|
|
|
6650
6681
|
catch (error) {
|
|
6651
6682
|
if (error instanceof AuthError)
|
|
6652
6683
|
throw error;
|
|
6653
|
-
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error
|
|
6684
|
+
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Sign in failed');
|
|
6654
6685
|
}
|
|
6655
6686
|
}
|
|
6656
6687
|
async signUp(phoneNumber, password) {
|
|
@@ -6714,7 +6745,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
|
|
|
6714
6745
|
catch (error) {
|
|
6715
6746
|
if (error instanceof AuthError)
|
|
6716
6747
|
throw error;
|
|
6717
|
-
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error
|
|
6748
|
+
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Sign up failed');
|
|
6718
6749
|
}
|
|
6719
6750
|
}
|
|
6720
6751
|
async sendVerificationCode(phoneNumber) {
|
|
@@ -6782,7 +6813,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
|
|
|
6782
6813
|
catch (error) {
|
|
6783
6814
|
if (error instanceof AuthError)
|
|
6784
6815
|
throw error;
|
|
6785
|
-
throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error
|
|
6816
|
+
throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Phone verification failed');
|
|
6786
6817
|
}
|
|
6787
6818
|
}
|
|
6788
6819
|
async signOut() {
|
|
@@ -6838,7 +6869,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
|
|
|
6838
6869
|
catch (error) {
|
|
6839
6870
|
if (error instanceof AuthError)
|
|
6840
6871
|
throw error;
|
|
6841
|
-
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
6872
|
+
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Token refresh failed');
|
|
6842
6873
|
}
|
|
6843
6874
|
}
|
|
6844
6875
|
async initialize() {
|
|
@@ -6877,6 +6908,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
|
|
|
6877
6908
|
// Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
|
|
6878
6909
|
// which has a different signature (this builds a phone-specific result from a backend payload).
|
|
6879
6910
|
buildAuthResult(data, phoneNumber, isNewUser = false) {
|
|
6911
|
+
var _a, _b;
|
|
6880
6912
|
const user = {
|
|
6881
6913
|
uid: data.uid || this.generateUid(phoneNumber),
|
|
6882
6914
|
email: data.email || null,
|
|
@@ -6900,8 +6932,8 @@ class PhonePasswordProvider extends BaseAuthProvider {
|
|
|
6900
6932
|
},
|
|
6901
6933
|
};
|
|
6902
6934
|
this.currentUser = user;
|
|
6903
|
-
this.storedAccessToken = data.accessToken;
|
|
6904
|
-
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;
|
|
6905
6937
|
return {
|
|
6906
6938
|
user,
|
|
6907
6939
|
credential: {
|