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/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
|
|
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({
|
|
@@ -5127,7 +5153,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
|
|
|
5127
5153
|
catch (error) {
|
|
5128
5154
|
if (error instanceof AuthError)
|
|
5129
5155
|
throw error;
|
|
5130
|
-
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error
|
|
5156
|
+
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with email and password');
|
|
5131
5157
|
}
|
|
5132
5158
|
}
|
|
5133
5159
|
async signUp(options) {
|
|
@@ -5212,7 +5238,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
|
|
|
5212
5238
|
catch (error) {
|
|
5213
5239
|
if (error instanceof AuthError)
|
|
5214
5240
|
throw error;
|
|
5215
|
-
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error
|
|
5241
|
+
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
|
|
5216
5242
|
}
|
|
5217
5243
|
}
|
|
5218
5244
|
async signOut() {
|
|
@@ -5278,7 +5304,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
|
|
|
5278
5304
|
catch (error) {
|
|
5279
5305
|
if (error instanceof AuthError)
|
|
5280
5306
|
throw error;
|
|
5281
|
-
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
5307
|
+
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
|
|
5282
5308
|
}
|
|
5283
5309
|
}
|
|
5284
5310
|
async updatePassword(currentPassword, newPassword) {
|
|
@@ -5314,7 +5340,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
|
|
|
5314
5340
|
catch (error) {
|
|
5315
5341
|
if (error instanceof AuthError)
|
|
5316
5342
|
throw error;
|
|
5317
|
-
throw new AuthError(AuthErrorCode.SERVER_ERROR, error
|
|
5343
|
+
throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
|
|
5318
5344
|
}
|
|
5319
5345
|
}
|
|
5320
5346
|
async sendPasswordResetEmail(email) {
|
|
@@ -5340,7 +5366,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
|
|
|
5340
5366
|
catch (error) {
|
|
5341
5367
|
if (error instanceof AuthError)
|
|
5342
5368
|
throw error;
|
|
5343
|
-
throw new AuthError(AuthErrorCode.SERVER_ERROR, error
|
|
5369
|
+
throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to send password reset email');
|
|
5344
5370
|
}
|
|
5345
5371
|
}
|
|
5346
5372
|
async sendEmailVerification() {
|
|
@@ -5369,7 +5395,7 @@ class EmailPasswordProvider extends BaseAuthProvider {
|
|
|
5369
5395
|
catch (error) {
|
|
5370
5396
|
if (error instanceof AuthError)
|
|
5371
5397
|
throw error;
|
|
5372
|
-
throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error
|
|
5398
|
+
throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Failed to send verification email');
|
|
5373
5399
|
}
|
|
5374
5400
|
}
|
|
5375
5401
|
isValidEmail(email) {
|
|
@@ -5433,7 +5459,9 @@ class BiometricProvider extends BaseAuthProvider {
|
|
|
5433
5459
|
async loadBiometricPlugin() {
|
|
5434
5460
|
try {
|
|
5435
5461
|
// Dynamic import to avoid errors if plugin not installed
|
|
5436
|
-
const { BiometricAuth } = await import(
|
|
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');
|
|
5437
5465
|
this.biometricAuth = BiometricAuth;
|
|
5438
5466
|
}
|
|
5439
5467
|
catch (_a) {
|
|
@@ -5441,7 +5469,6 @@ class BiometricProvider extends BaseAuthProvider {
|
|
|
5441
5469
|
}
|
|
5442
5470
|
}
|
|
5443
5471
|
async signIn(_options) {
|
|
5444
|
-
var _a, _b, _c;
|
|
5445
5472
|
if (!this.biometricAuth) {
|
|
5446
5473
|
throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, 'Biometric authentication plugin is not installed. Please install capacitor-biometric-authentication');
|
|
5447
5474
|
}
|
|
@@ -5496,18 +5523,22 @@ class BiometricProvider extends BaseAuthProvider {
|
|
|
5496
5523
|
if (error instanceof AuthError)
|
|
5497
5524
|
throw error;
|
|
5498
5525
|
// Handle biometric errors
|
|
5499
|
-
|
|
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'))) {
|
|
5500
5531
|
throw new AuthError(AuthErrorCode.USER_CANCELLED, 'Authentication cancelled by user');
|
|
5501
5532
|
}
|
|
5502
|
-
else if (
|
|
5503
|
-
(
|
|
5533
|
+
else if (errorCode === 'biometryLockout' ||
|
|
5534
|
+
(errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('lockout'))) {
|
|
5504
5535
|
throw new AuthError(AuthErrorCode.BIOMETRIC_LOCKOUT, 'Too many failed attempts. Biometry is locked.');
|
|
5505
5536
|
}
|
|
5506
|
-
else if (
|
|
5507
|
-
(
|
|
5537
|
+
else if (errorCode === 'biometryNotEnrolled' ||
|
|
5538
|
+
(errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('enrolled'))) {
|
|
5508
5539
|
throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_ENROLLED, 'No biometric credentials are enrolled');
|
|
5509
5540
|
}
|
|
5510
|
-
throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED,
|
|
5541
|
+
throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, errorMessage || 'Biometric authentication failed');
|
|
5511
5542
|
}
|
|
5512
5543
|
}
|
|
5513
5544
|
async signOut() {
|
|
@@ -6066,7 +6097,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
|
|
|
6066
6097
|
catch (error) {
|
|
6067
6098
|
if (error instanceof AuthError)
|
|
6068
6099
|
throw error;
|
|
6069
|
-
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error
|
|
6100
|
+
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with username and password');
|
|
6070
6101
|
}
|
|
6071
6102
|
}
|
|
6072
6103
|
async signUp(options) {
|
|
@@ -6158,7 +6189,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
|
|
|
6158
6189
|
catch (error) {
|
|
6159
6190
|
if (error instanceof AuthError)
|
|
6160
6191
|
throw error;
|
|
6161
|
-
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error
|
|
6192
|
+
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
|
|
6162
6193
|
}
|
|
6163
6194
|
}
|
|
6164
6195
|
async signOut() {
|
|
@@ -6224,7 +6255,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
|
|
|
6224
6255
|
catch (error) {
|
|
6225
6256
|
if (error instanceof AuthError)
|
|
6226
6257
|
throw error;
|
|
6227
|
-
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
6258
|
+
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
|
|
6228
6259
|
}
|
|
6229
6260
|
}
|
|
6230
6261
|
async updatePassword(currentPassword, newPassword) {
|
|
@@ -6260,7 +6291,7 @@ class UsernamePasswordProvider extends BaseAuthProvider {
|
|
|
6260
6291
|
catch (error) {
|
|
6261
6292
|
if (error instanceof AuthError)
|
|
6262
6293
|
throw error;
|
|
6263
|
-
throw new AuthError(AuthErrorCode.SERVER_ERROR, error
|
|
6294
|
+
throw new AuthError(AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
|
|
6264
6295
|
}
|
|
6265
6296
|
}
|
|
6266
6297
|
async checkUsernameAvailability(username) {
|
|
@@ -6667,7 +6698,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
|
|
|
6667
6698
|
catch (error) {
|
|
6668
6699
|
if (error instanceof AuthError)
|
|
6669
6700
|
throw error;
|
|
6670
|
-
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error
|
|
6701
|
+
throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Sign in failed');
|
|
6671
6702
|
}
|
|
6672
6703
|
}
|
|
6673
6704
|
async signUp(phoneNumber, password) {
|
|
@@ -6731,7 +6762,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
|
|
|
6731
6762
|
catch (error) {
|
|
6732
6763
|
if (error instanceof AuthError)
|
|
6733
6764
|
throw error;
|
|
6734
|
-
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, error
|
|
6765
|
+
throw new AuthError(AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Sign up failed');
|
|
6735
6766
|
}
|
|
6736
6767
|
}
|
|
6737
6768
|
async sendVerificationCode(phoneNumber) {
|
|
@@ -6799,7 +6830,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
|
|
|
6799
6830
|
catch (error) {
|
|
6800
6831
|
if (error instanceof AuthError)
|
|
6801
6832
|
throw error;
|
|
6802
|
-
throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, error
|
|
6833
|
+
throw new AuthError(AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Phone verification failed');
|
|
6803
6834
|
}
|
|
6804
6835
|
}
|
|
6805
6836
|
async signOut() {
|
|
@@ -6855,7 +6886,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
|
|
|
6855
6886
|
catch (error) {
|
|
6856
6887
|
if (error instanceof AuthError)
|
|
6857
6888
|
throw error;
|
|
6858
|
-
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
6889
|
+
throw new AuthError(AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Token refresh failed');
|
|
6859
6890
|
}
|
|
6860
6891
|
}
|
|
6861
6892
|
async initialize() {
|
|
@@ -6894,6 +6925,7 @@ class PhonePasswordProvider extends BaseAuthProvider {
|
|
|
6894
6925
|
// Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
|
|
6895
6926
|
// which has a different signature (this builds a phone-specific result from a backend payload).
|
|
6896
6927
|
buildAuthResult(data, phoneNumber, isNewUser = false) {
|
|
6928
|
+
var _a, _b;
|
|
6897
6929
|
const user = {
|
|
6898
6930
|
uid: data.uid || this.generateUid(phoneNumber),
|
|
6899
6931
|
email: data.email || null,
|
|
@@ -6917,8 +6949,8 @@ class PhonePasswordProvider extends BaseAuthProvider {
|
|
|
6917
6949
|
},
|
|
6918
6950
|
};
|
|
6919
6951
|
this.currentUser = user;
|
|
6920
|
-
this.storedAccessToken = data.accessToken;
|
|
6921
|
-
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;
|
|
6922
6954
|
return {
|
|
6923
6955
|
user,
|
|
6924
6956
|
credential: {
|