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/plugin.js
CHANGED
|
@@ -433,7 +433,9 @@ var CapacitorAuthManager = (function (exports, core) {
|
|
|
433
433
|
}
|
|
434
434
|
getPrefs() {
|
|
435
435
|
if (!this.prefsPromise) {
|
|
436
|
-
this.prefsPromise = import(
|
|
436
|
+
this.prefsPromise = import(
|
|
437
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- optional peer dep; the module may be absent at build time
|
|
438
|
+
'@capacitor/preferences').then((m) => m.Preferences);
|
|
437
439
|
}
|
|
438
440
|
return this.prefsPromise;
|
|
439
441
|
}
|
|
@@ -679,6 +681,27 @@ var CapacitorAuthManager = (function (exports, core) {
|
|
|
679
681
|
}
|
|
680
682
|
PlatformDetector.platformInfo = null;
|
|
681
683
|
|
|
684
|
+
/**
|
|
685
|
+
* Safely extract a human-readable message from an unknown thrown value.
|
|
686
|
+
*
|
|
687
|
+
* `catch` clauses receive `unknown` (the honest type — anything can be thrown), so reach for this
|
|
688
|
+
* instead of typing the binding as `any`. Returns `undefined` when no message can be derived, so
|
|
689
|
+
* callers can fall back to their own default text: `getErrorMessage(error) || 'Default message'`.
|
|
690
|
+
*/
|
|
691
|
+
function getErrorMessage(error) {
|
|
692
|
+
if (error instanceof Error) {
|
|
693
|
+
return error.message;
|
|
694
|
+
}
|
|
695
|
+
if (typeof error === 'object' && error !== null && 'message' in error) {
|
|
696
|
+
const message = error.message;
|
|
697
|
+
return typeof message === 'string' ? message : undefined;
|
|
698
|
+
}
|
|
699
|
+
if (typeof error === 'string') {
|
|
700
|
+
return error;
|
|
701
|
+
}
|
|
702
|
+
return undefined;
|
|
703
|
+
}
|
|
704
|
+
|
|
682
705
|
/**
|
|
683
706
|
* Built-in provider manifests (display metadata + human-readable setup instructions).
|
|
684
707
|
*
|
|
@@ -1166,7 +1189,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
1166
1189
|
return (_b = this.NAME_ALIASES[name]) !== null && _b !== void 0 ? _b : name;
|
|
1167
1190
|
}
|
|
1168
1191
|
static async getProvider(name, options, deps) {
|
|
1169
|
-
var _b, _c
|
|
1192
|
+
var _b, _c;
|
|
1170
1193
|
const key = this.canonicalName(name);
|
|
1171
1194
|
// Check if already loaded
|
|
1172
1195
|
const existing = this.providers.get(key);
|
|
@@ -1191,7 +1214,9 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
1191
1214
|
}
|
|
1192
1215
|
}
|
|
1193
1216
|
try {
|
|
1194
|
-
// Load the provider class
|
|
1217
|
+
// Load the provider class. Every loader resolves to `{ default: <ProviderConstructor> }`
|
|
1218
|
+
// (see registerLoader calls above); narrow `default` to that constructor shape so the
|
|
1219
|
+
// `new ProviderClass(...)` below type-checks without resorting to `any`.
|
|
1195
1220
|
const module = await loader();
|
|
1196
1221
|
const ProviderClass = module.default;
|
|
1197
1222
|
// Build the constructor argument. BaseAuthProvider subclasses need a full
|
|
@@ -1224,8 +1249,9 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
1224
1249
|
}
|
|
1225
1250
|
catch (error) {
|
|
1226
1251
|
// Check if it's a missing dependency error
|
|
1227
|
-
|
|
1228
|
-
|
|
1252
|
+
const message = getErrorMessage(error);
|
|
1253
|
+
if ((message === null || message === void 0 ? void 0 : message.includes('Cannot find module')) ||
|
|
1254
|
+
(message === null || message === void 0 ? void 0 : message.includes('Failed to resolve module'))) {
|
|
1229
1255
|
const manifest = this.manifests.get(this.canonicalName(name));
|
|
1230
1256
|
if (manifest === null || manifest === void 0 ? void 0 : manifest.packageName) {
|
|
1231
1257
|
throw new Error(`Missing dependency for ${manifest.displayName} provider.\n\n` +
|
|
@@ -1478,6 +1504,8 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
1478
1504
|
// email/password/phoneNumber/username) AND kept nested under `credentials` for
|
|
1479
1505
|
// providers that read them there.
|
|
1480
1506
|
this.logger.info(`Signing in with ${providerName}`);
|
|
1507
|
+
// The provider reads credentials/options from this merged shape; `provider` is supplied via
|
|
1508
|
+
// construction, not here, so we assert to SignInOptions (whose `provider` is required).
|
|
1481
1509
|
const result = await provider.signIn(Object.assign(Object.assign(Object.assign({}, signInOptions.options), ((_b = signInOptions.credentials) !== null && _b !== void 0 ? _b : {})), { credentials: signInOptions.credentials }));
|
|
1482
1510
|
// Update state
|
|
1483
1511
|
this.updateState({
|
|
@@ -4884,7 +4912,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
4884
4912
|
catch (error) {
|
|
4885
4913
|
if (error instanceof AuthError)
|
|
4886
4914
|
throw error;
|
|
4887
|
-
throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, error
|
|
4915
|
+
throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with email and password');
|
|
4888
4916
|
}
|
|
4889
4917
|
}
|
|
4890
4918
|
async signUp(options) {
|
|
@@ -4969,7 +4997,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
4969
4997
|
catch (error) {
|
|
4970
4998
|
if (error instanceof AuthError)
|
|
4971
4999
|
throw error;
|
|
4972
|
-
throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, error
|
|
5000
|
+
throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
|
|
4973
5001
|
}
|
|
4974
5002
|
}
|
|
4975
5003
|
async signOut() {
|
|
@@ -5035,7 +5063,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
5035
5063
|
catch (error) {
|
|
5036
5064
|
if (error instanceof AuthError)
|
|
5037
5065
|
throw error;
|
|
5038
|
-
throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
5066
|
+
throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
|
|
5039
5067
|
}
|
|
5040
5068
|
}
|
|
5041
5069
|
async updatePassword(currentPassword, newPassword) {
|
|
@@ -5071,7 +5099,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
5071
5099
|
catch (error) {
|
|
5072
5100
|
if (error instanceof AuthError)
|
|
5073
5101
|
throw error;
|
|
5074
|
-
throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, error
|
|
5102
|
+
throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
|
|
5075
5103
|
}
|
|
5076
5104
|
}
|
|
5077
5105
|
async sendPasswordResetEmail(email) {
|
|
@@ -5097,7 +5125,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
5097
5125
|
catch (error) {
|
|
5098
5126
|
if (error instanceof AuthError)
|
|
5099
5127
|
throw error;
|
|
5100
|
-
throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, error
|
|
5128
|
+
throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to send password reset email');
|
|
5101
5129
|
}
|
|
5102
5130
|
}
|
|
5103
5131
|
async sendEmailVerification() {
|
|
@@ -5126,7 +5154,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
5126
5154
|
catch (error) {
|
|
5127
5155
|
if (error instanceof AuthError)
|
|
5128
5156
|
throw error;
|
|
5129
|
-
throw new AuthError(exports.AuthErrorCode.VERIFICATION_FAILED, error
|
|
5157
|
+
throw new AuthError(exports.AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Failed to send verification email');
|
|
5130
5158
|
}
|
|
5131
5159
|
}
|
|
5132
5160
|
isValidEmail(email) {
|
|
@@ -5190,7 +5218,9 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
5190
5218
|
async loadBiometricPlugin() {
|
|
5191
5219
|
try {
|
|
5192
5220
|
// Dynamic import to avoid errors if plugin not installed
|
|
5193
|
-
const { BiometricAuth } = await import(
|
|
5221
|
+
const { BiometricAuth } = await import(
|
|
5222
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- optional peer dep; module may be absent at build time
|
|
5223
|
+
'capacitor-biometric-authentication');
|
|
5194
5224
|
this.biometricAuth = BiometricAuth;
|
|
5195
5225
|
}
|
|
5196
5226
|
catch (_a) {
|
|
@@ -5198,7 +5228,6 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
5198
5228
|
}
|
|
5199
5229
|
}
|
|
5200
5230
|
async signIn(_options) {
|
|
5201
|
-
var _a, _b, _c;
|
|
5202
5231
|
if (!this.biometricAuth) {
|
|
5203
5232
|
throw new AuthError(exports.AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, 'Biometric authentication plugin is not installed. Please install capacitor-biometric-authentication');
|
|
5204
5233
|
}
|
|
@@ -5253,18 +5282,22 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
5253
5282
|
if (error instanceof AuthError)
|
|
5254
5283
|
throw error;
|
|
5255
5284
|
// Handle biometric errors
|
|
5256
|
-
|
|
5285
|
+
const errorCode = typeof error === 'object' && error !== null && 'code' in error
|
|
5286
|
+
? error.code
|
|
5287
|
+
: undefined;
|
|
5288
|
+
const errorMessage = getErrorMessage(error);
|
|
5289
|
+
if (errorCode === 'userCancel' || (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('cancel'))) {
|
|
5257
5290
|
throw new AuthError(exports.AuthErrorCode.USER_CANCELLED, 'Authentication cancelled by user');
|
|
5258
5291
|
}
|
|
5259
|
-
else if (
|
|
5260
|
-
(
|
|
5292
|
+
else if (errorCode === 'biometryLockout' ||
|
|
5293
|
+
(errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('lockout'))) {
|
|
5261
5294
|
throw new AuthError(exports.AuthErrorCode.BIOMETRIC_LOCKOUT, 'Too many failed attempts. Biometry is locked.');
|
|
5262
5295
|
}
|
|
5263
|
-
else if (
|
|
5264
|
-
(
|
|
5296
|
+
else if (errorCode === 'biometryNotEnrolled' ||
|
|
5297
|
+
(errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('enrolled'))) {
|
|
5265
5298
|
throw new AuthError(exports.AuthErrorCode.BIOMETRIC_NOT_ENROLLED, 'No biometric credentials are enrolled');
|
|
5266
5299
|
}
|
|
5267
|
-
throw new AuthError(exports.AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED,
|
|
5300
|
+
throw new AuthError(exports.AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, errorMessage || 'Biometric authentication failed');
|
|
5268
5301
|
}
|
|
5269
5302
|
}
|
|
5270
5303
|
async signOut() {
|
|
@@ -5823,7 +5856,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
5823
5856
|
catch (error) {
|
|
5824
5857
|
if (error instanceof AuthError)
|
|
5825
5858
|
throw error;
|
|
5826
|
-
throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, error
|
|
5859
|
+
throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with username and password');
|
|
5827
5860
|
}
|
|
5828
5861
|
}
|
|
5829
5862
|
async signUp(options) {
|
|
@@ -5915,7 +5948,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
5915
5948
|
catch (error) {
|
|
5916
5949
|
if (error instanceof AuthError)
|
|
5917
5950
|
throw error;
|
|
5918
|
-
throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, error
|
|
5951
|
+
throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
|
|
5919
5952
|
}
|
|
5920
5953
|
}
|
|
5921
5954
|
async signOut() {
|
|
@@ -5981,7 +6014,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
5981
6014
|
catch (error) {
|
|
5982
6015
|
if (error instanceof AuthError)
|
|
5983
6016
|
throw error;
|
|
5984
|
-
throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
6017
|
+
throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
|
|
5985
6018
|
}
|
|
5986
6019
|
}
|
|
5987
6020
|
async updatePassword(currentPassword, newPassword) {
|
|
@@ -6017,7 +6050,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
6017
6050
|
catch (error) {
|
|
6018
6051
|
if (error instanceof AuthError)
|
|
6019
6052
|
throw error;
|
|
6020
|
-
throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, error
|
|
6053
|
+
throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
|
|
6021
6054
|
}
|
|
6022
6055
|
}
|
|
6023
6056
|
async checkUsernameAvailability(username) {
|
|
@@ -6424,7 +6457,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
6424
6457
|
catch (error) {
|
|
6425
6458
|
if (error instanceof AuthError)
|
|
6426
6459
|
throw error;
|
|
6427
|
-
throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, error
|
|
6460
|
+
throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Sign in failed');
|
|
6428
6461
|
}
|
|
6429
6462
|
}
|
|
6430
6463
|
async signUp(phoneNumber, password) {
|
|
@@ -6488,7 +6521,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
6488
6521
|
catch (error) {
|
|
6489
6522
|
if (error instanceof AuthError)
|
|
6490
6523
|
throw error;
|
|
6491
|
-
throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, error
|
|
6524
|
+
throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Sign up failed');
|
|
6492
6525
|
}
|
|
6493
6526
|
}
|
|
6494
6527
|
async sendVerificationCode(phoneNumber) {
|
|
@@ -6556,7 +6589,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
6556
6589
|
catch (error) {
|
|
6557
6590
|
if (error instanceof AuthError)
|
|
6558
6591
|
throw error;
|
|
6559
|
-
throw new AuthError(exports.AuthErrorCode.VERIFICATION_FAILED, error
|
|
6592
|
+
throw new AuthError(exports.AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Phone verification failed');
|
|
6560
6593
|
}
|
|
6561
6594
|
}
|
|
6562
6595
|
async signOut() {
|
|
@@ -6612,7 +6645,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
6612
6645
|
catch (error) {
|
|
6613
6646
|
if (error instanceof AuthError)
|
|
6614
6647
|
throw error;
|
|
6615
|
-
throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
6648
|
+
throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Token refresh failed');
|
|
6616
6649
|
}
|
|
6617
6650
|
}
|
|
6618
6651
|
async initialize() {
|
|
@@ -6651,6 +6684,7 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
6651
6684
|
// Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
|
|
6652
6685
|
// which has a different signature (this builds a phone-specific result from a backend payload).
|
|
6653
6686
|
buildAuthResult(data, phoneNumber, isNewUser = false) {
|
|
6687
|
+
var _a, _b;
|
|
6654
6688
|
const user = {
|
|
6655
6689
|
uid: data.uid || this.generateUid(phoneNumber),
|
|
6656
6690
|
email: data.email || null,
|
|
@@ -6674,8 +6708,8 @@ Note: This provider requires a backend service to handle authentication.
|
|
|
6674
6708
|
},
|
|
6675
6709
|
};
|
|
6676
6710
|
this.currentUser = user;
|
|
6677
|
-
this.storedAccessToken = data.accessToken;
|
|
6678
|
-
this.storedRefreshToken = data.refreshToken;
|
|
6711
|
+
this.storedAccessToken = (_a = data.accessToken) !== null && _a !== void 0 ? _a : null;
|
|
6712
|
+
this.storedRefreshToken = (_b = data.refreshToken) !== null && _b !== void 0 ? _b : null;
|
|
6679
6713
|
return {
|
|
6680
6714
|
user,
|
|
6681
6715
|
credential: {
|