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/plugin.cjs.js
CHANGED
|
@@ -434,7 +434,9 @@ class CapacitorPreferencesStorage {
|
|
|
434
434
|
}
|
|
435
435
|
getPrefs() {
|
|
436
436
|
if (!this.prefsPromise) {
|
|
437
|
-
this.prefsPromise = import(
|
|
437
|
+
this.prefsPromise = import(
|
|
438
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- optional peer dep; the module may be absent at build time
|
|
439
|
+
'@capacitor/preferences').then((m) => m.Preferences);
|
|
438
440
|
}
|
|
439
441
|
return this.prefsPromise;
|
|
440
442
|
}
|
|
@@ -680,6 +682,27 @@ class PlatformDetector {
|
|
|
680
682
|
}
|
|
681
683
|
PlatformDetector.platformInfo = null;
|
|
682
684
|
|
|
685
|
+
/**
|
|
686
|
+
* Safely extract a human-readable message from an unknown thrown value.
|
|
687
|
+
*
|
|
688
|
+
* `catch` clauses receive `unknown` (the honest type — anything can be thrown), so reach for this
|
|
689
|
+
* instead of typing the binding as `any`. Returns `undefined` when no message can be derived, so
|
|
690
|
+
* callers can fall back to their own default text: `getErrorMessage(error) || 'Default message'`.
|
|
691
|
+
*/
|
|
692
|
+
function getErrorMessage(error) {
|
|
693
|
+
if (error instanceof Error) {
|
|
694
|
+
return error.message;
|
|
695
|
+
}
|
|
696
|
+
if (typeof error === 'object' && error !== null && 'message' in error) {
|
|
697
|
+
const message = error.message;
|
|
698
|
+
return typeof message === 'string' ? message : undefined;
|
|
699
|
+
}
|
|
700
|
+
if (typeof error === 'string') {
|
|
701
|
+
return error;
|
|
702
|
+
}
|
|
703
|
+
return undefined;
|
|
704
|
+
}
|
|
705
|
+
|
|
683
706
|
/**
|
|
684
707
|
* Built-in provider manifests (display metadata + human-readable setup instructions).
|
|
685
708
|
*
|
|
@@ -1167,7 +1190,7 @@ class ProviderRegistry {
|
|
|
1167
1190
|
return (_b = this.NAME_ALIASES[name]) !== null && _b !== void 0 ? _b : name;
|
|
1168
1191
|
}
|
|
1169
1192
|
static async getProvider(name, options, deps) {
|
|
1170
|
-
var _b, _c
|
|
1193
|
+
var _b, _c;
|
|
1171
1194
|
const key = this.canonicalName(name);
|
|
1172
1195
|
// Check if already loaded
|
|
1173
1196
|
const existing = this.providers.get(key);
|
|
@@ -1192,7 +1215,9 @@ class ProviderRegistry {
|
|
|
1192
1215
|
}
|
|
1193
1216
|
}
|
|
1194
1217
|
try {
|
|
1195
|
-
// Load the provider class
|
|
1218
|
+
// Load the provider class. Every loader resolves to `{ default: <ProviderConstructor> }`
|
|
1219
|
+
// (see registerLoader calls above); narrow `default` to that constructor shape so the
|
|
1220
|
+
// `new ProviderClass(...)` below type-checks without resorting to `any`.
|
|
1196
1221
|
const module = await loader();
|
|
1197
1222
|
const ProviderClass = module.default;
|
|
1198
1223
|
// Build the constructor argument. BaseAuthProvider subclasses need a full
|
|
@@ -1225,8 +1250,9 @@ class ProviderRegistry {
|
|
|
1225
1250
|
}
|
|
1226
1251
|
catch (error) {
|
|
1227
1252
|
// Check if it's a missing dependency error
|
|
1228
|
-
|
|
1229
|
-
|
|
1253
|
+
const message = getErrorMessage(error);
|
|
1254
|
+
if ((message === null || message === void 0 ? void 0 : message.includes('Cannot find module')) ||
|
|
1255
|
+
(message === null || message === void 0 ? void 0 : message.includes('Failed to resolve module'))) {
|
|
1230
1256
|
const manifest = this.manifests.get(this.canonicalName(name));
|
|
1231
1257
|
if (manifest === null || manifest === void 0 ? void 0 : manifest.packageName) {
|
|
1232
1258
|
throw new Error(`Missing dependency for ${manifest.displayName} provider.\n\n` +
|
|
@@ -1479,6 +1505,8 @@ class AuthManagerCore {
|
|
|
1479
1505
|
// email/password/phoneNumber/username) AND kept nested under `credentials` for
|
|
1480
1506
|
// providers that read them there.
|
|
1481
1507
|
this.logger.info(`Signing in with ${providerName}`);
|
|
1508
|
+
// The provider reads credentials/options from this merged shape; `provider` is supplied via
|
|
1509
|
+
// construction, not here, so we assert to SignInOptions (whose `provider` is required).
|
|
1482
1510
|
const result = await provider.signIn(Object.assign(Object.assign(Object.assign({}, signInOptions.options), ((_b = signInOptions.credentials) !== null && _b !== void 0 ? _b : {})), { credentials: signInOptions.credentials }));
|
|
1483
1511
|
// Update state
|
|
1484
1512
|
this.updateState({
|
|
@@ -1899,6 +1927,31 @@ const CapacitorAuthManager = core.registerPlugin('CapacitorAuthManager', {
|
|
|
1899
1927
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorAuthManagerWeb()),
|
|
1900
1928
|
});
|
|
1901
1929
|
|
|
1930
|
+
/**
|
|
1931
|
+
* Normalize a provider constructor argument into a full {@link BaseProviderConfig}.
|
|
1932
|
+
*
|
|
1933
|
+
* The standalone providers are public (exported from `capacitor-auth-manager/providers/web`) and
|
|
1934
|
+
* get constructed two ways: the factory/registry pass a full {@link BaseProviderConfig}, while
|
|
1935
|
+
* tests and direct consumers pass the provider's own bare options object. This helper accepts
|
|
1936
|
+
* either — a bare object is wrapped with an in-memory storage (`AuthPersistence.NONE`, so it never
|
|
1937
|
+
* touches `window` and stays safe under SSR / Node test environments) plus the shared
|
|
1938
|
+
* {@link defaultLogger}. Callers that pass a full config keep their injected storage/logger.
|
|
1939
|
+
*/
|
|
1940
|
+
function resolveProviderConfig(provider, input) {
|
|
1941
|
+
if (typeof input === 'object' &&
|
|
1942
|
+
input !== null &&
|
|
1943
|
+
'storage' in input &&
|
|
1944
|
+
'logger' in input &&
|
|
1945
|
+
'options' in input) {
|
|
1946
|
+
return input;
|
|
1947
|
+
}
|
|
1948
|
+
return {
|
|
1949
|
+
provider,
|
|
1950
|
+
options: (input !== null && input !== void 0 ? input : {}),
|
|
1951
|
+
storage: new WebStorage(exports.AuthPersistence.NONE),
|
|
1952
|
+
logger: defaultLogger,
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1902
1955
|
class BaseAuthProvider {
|
|
1903
1956
|
get name() {
|
|
1904
1957
|
return this.provider;
|
|
@@ -1918,13 +1971,13 @@ class BaseAuthProvider {
|
|
|
1918
1971
|
// across every provider (see AuthProviderInterface, where they are optional). Marking them
|
|
1919
1972
|
// abstract previously forced every subclass to re-implement them just to throw.
|
|
1920
1973
|
async linkAccount(_options) {
|
|
1921
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `
|
|
1974
|
+
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Account linking is not supported by provider ${this.provider}`, this.provider);
|
|
1922
1975
|
}
|
|
1923
1976
|
async unlinkAccount(_options) {
|
|
1924
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `
|
|
1977
|
+
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Account unlinking is not supported by provider ${this.provider}`, this.provider);
|
|
1925
1978
|
}
|
|
1926
1979
|
async revokeAccess(_token) {
|
|
1927
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `
|
|
1980
|
+
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Access revocation is not supported by provider ${this.provider}`, this.provider);
|
|
1928
1981
|
}
|
|
1929
1982
|
async getCurrentUser() {
|
|
1930
1983
|
if (!this.isInitialized) {
|
|
@@ -4239,16 +4292,19 @@ class PendingVerificationStore {
|
|
|
4239
4292
|
}
|
|
4240
4293
|
}
|
|
4241
4294
|
|
|
4242
|
-
class MagicLinkProvider {
|
|
4243
|
-
|
|
4244
|
-
|
|
4295
|
+
class MagicLinkProvider extends BaseAuthProvider {
|
|
4296
|
+
get name() {
|
|
4297
|
+
return 'magic-link';
|
|
4298
|
+
}
|
|
4299
|
+
constructor(input) {
|
|
4300
|
+
super(resolveProviderConfig(exports.AuthProvider.EMAIL_MAGIC_LINK, input));
|
|
4245
4301
|
// Persisted (SSR-guarded localStorage) so a magic link clicked from an email — which opens a
|
|
4246
4302
|
// FRESH page load with empty in-memory state — can still find its pending entry to verify
|
|
4247
4303
|
// against. Keyed by the link token (already present in the callback URL); we store only the
|
|
4248
4304
|
// email + expiry, never any additional secret (see PendingVerificationStore + F-11).
|
|
4249
4305
|
this.pendingVerification = new PendingVerificationStore('magic-link');
|
|
4250
|
-
//
|
|
4251
|
-
this.config =
|
|
4306
|
+
// Magic link uses its config as-is (no defaults to merge).
|
|
4307
|
+
this.config = this.options;
|
|
4252
4308
|
// Check for magic link callback on initialization
|
|
4253
4309
|
this.checkForMagicLinkCallback();
|
|
4254
4310
|
}
|
|
@@ -4498,14 +4554,9 @@ class MagicLinkProvider {
|
|
|
4498
4554
|
// Magic link auth is supported if we have the required config
|
|
4499
4555
|
return !!this.config.sendLinkUrl;
|
|
4500
4556
|
}
|
|
4501
|
-
|
|
4502
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for magic link authentication');
|
|
4503
|
-
}
|
|
4504
|
-
async unlinkAccount(_options) {
|
|
4505
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for magic link authentication');
|
|
4506
|
-
}
|
|
4557
|
+
// linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
|
|
4507
4558
|
async revokeAccess(_token) {
|
|
4508
|
-
// Magic link doesn't have persistent access to revoke
|
|
4559
|
+
// Magic link doesn't have persistent access to revoke; clear any pending verification.
|
|
4509
4560
|
this.pendingVerification.clear();
|
|
4510
4561
|
}
|
|
4511
4562
|
}
|
|
@@ -4515,16 +4566,18 @@ var magicLinkProvider = /*#__PURE__*/Object.freeze({
|
|
|
4515
4566
|
MagicLinkProvider: MagicLinkProvider
|
|
4516
4567
|
});
|
|
4517
4568
|
|
|
4518
|
-
class SMSProvider {
|
|
4519
|
-
|
|
4520
|
-
|
|
4569
|
+
class SMSProvider extends BaseAuthProvider {
|
|
4570
|
+
get name() {
|
|
4571
|
+
return 'sms';
|
|
4572
|
+
}
|
|
4573
|
+
constructor(input) {
|
|
4574
|
+
super(resolveProviderConfig(exports.AuthProvider.SMS, input));
|
|
4521
4575
|
// Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
|
|
4522
4576
|
// page change between sending and verifying the code. Only non-secret metadata is stored —
|
|
4523
4577
|
// never the SMS code itself (see PendingVerificationStore + F-11).
|
|
4524
4578
|
this.pendingVerifications = new PendingVerificationStore('sms');
|
|
4525
4579
|
this.MAX_ATTEMPTS = 3;
|
|
4526
|
-
|
|
4527
|
-
this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, config);
|
|
4580
|
+
this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, this.options);
|
|
4528
4581
|
}
|
|
4529
4582
|
async signIn(options) {
|
|
4530
4583
|
if (!(options === null || options === void 0 ? void 0 : options.phoneNumber)) {
|
|
@@ -4762,14 +4815,9 @@ class SMSProvider {
|
|
|
4762
4815
|
// SMS auth is supported if we have the required config
|
|
4763
4816
|
return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
|
|
4764
4817
|
}
|
|
4765
|
-
|
|
4766
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for SMS authentication');
|
|
4767
|
-
}
|
|
4768
|
-
async unlinkAccount(_options) {
|
|
4769
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for SMS authentication');
|
|
4770
|
-
}
|
|
4818
|
+
// linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
|
|
4771
4819
|
async revokeAccess(_token) {
|
|
4772
|
-
// SMS auth doesn't have persistent access to revoke
|
|
4820
|
+
// SMS auth doesn't have persistent access to revoke; clear any pending verification.
|
|
4773
4821
|
this.pendingVerifications.clear();
|
|
4774
4822
|
}
|
|
4775
4823
|
}
|
|
@@ -4779,20 +4827,23 @@ var smsProvider = /*#__PURE__*/Object.freeze({
|
|
|
4779
4827
|
SMSProvider: SMSProvider
|
|
4780
4828
|
});
|
|
4781
4829
|
|
|
4782
|
-
class EmailPasswordProvider {
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4830
|
+
class EmailPasswordProvider extends BaseAuthProvider {
|
|
4831
|
+
get name() {
|
|
4832
|
+
return 'email-password';
|
|
4833
|
+
}
|
|
4834
|
+
constructor(input) {
|
|
4835
|
+
super(resolveProviderConfig(exports.AuthProvider.EMAIL_PASSWORD, input));
|
|
4836
|
+
// currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
|
|
4837
|
+
// so email/password sessions stay in-memory exactly as before (no new storage persistence).
|
|
4786
4838
|
this.authToken = null;
|
|
4787
4839
|
this.refreshTokenValue = null;
|
|
4788
|
-
// Initialize with config
|
|
4789
4840
|
this.config = Object.assign({ allowSignUp: true, passwordRequirements: {
|
|
4790
4841
|
minLength: 8,
|
|
4791
4842
|
requireUppercase: true,
|
|
4792
4843
|
requireLowercase: true,
|
|
4793
4844
|
requireNumbers: true,
|
|
4794
4845
|
requireSpecialChars: false,
|
|
4795
|
-
} },
|
|
4846
|
+
} }, this.options);
|
|
4796
4847
|
}
|
|
4797
4848
|
async signIn(options) {
|
|
4798
4849
|
if (!(options === null || options === void 0 ? void 0 : options.email) || !(options === null || options === void 0 ? void 0 : options.password)) {
|
|
@@ -4862,7 +4913,7 @@ class EmailPasswordProvider {
|
|
|
4862
4913
|
catch (error) {
|
|
4863
4914
|
if (error instanceof AuthError)
|
|
4864
4915
|
throw error;
|
|
4865
|
-
throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, error
|
|
4916
|
+
throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with email and password');
|
|
4866
4917
|
}
|
|
4867
4918
|
}
|
|
4868
4919
|
async signUp(options) {
|
|
@@ -4947,7 +4998,7 @@ class EmailPasswordProvider {
|
|
|
4947
4998
|
catch (error) {
|
|
4948
4999
|
if (error instanceof AuthError)
|
|
4949
5000
|
throw error;
|
|
4950
|
-
throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, error
|
|
5001
|
+
throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
|
|
4951
5002
|
}
|
|
4952
5003
|
}
|
|
4953
5004
|
async signOut() {
|
|
@@ -5013,7 +5064,7 @@ class EmailPasswordProvider {
|
|
|
5013
5064
|
catch (error) {
|
|
5014
5065
|
if (error instanceof AuthError)
|
|
5015
5066
|
throw error;
|
|
5016
|
-
throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
5067
|
+
throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
|
|
5017
5068
|
}
|
|
5018
5069
|
}
|
|
5019
5070
|
async updatePassword(currentPassword, newPassword) {
|
|
@@ -5049,7 +5100,7 @@ class EmailPasswordProvider {
|
|
|
5049
5100
|
catch (error) {
|
|
5050
5101
|
if (error instanceof AuthError)
|
|
5051
5102
|
throw error;
|
|
5052
|
-
throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, error
|
|
5103
|
+
throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
|
|
5053
5104
|
}
|
|
5054
5105
|
}
|
|
5055
5106
|
async sendPasswordResetEmail(email) {
|
|
@@ -5075,7 +5126,7 @@ class EmailPasswordProvider {
|
|
|
5075
5126
|
catch (error) {
|
|
5076
5127
|
if (error instanceof AuthError)
|
|
5077
5128
|
throw error;
|
|
5078
|
-
throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, error
|
|
5129
|
+
throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to send password reset email');
|
|
5079
5130
|
}
|
|
5080
5131
|
}
|
|
5081
5132
|
async sendEmailVerification() {
|
|
@@ -5104,7 +5155,7 @@ class EmailPasswordProvider {
|
|
|
5104
5155
|
catch (error) {
|
|
5105
5156
|
if (error instanceof AuthError)
|
|
5106
5157
|
throw error;
|
|
5107
|
-
throw new AuthError(exports.AuthErrorCode.VERIFICATION_FAILED, error
|
|
5158
|
+
throw new AuthError(exports.AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Failed to send verification email');
|
|
5108
5159
|
}
|
|
5109
5160
|
}
|
|
5110
5161
|
isValidEmail(email) {
|
|
@@ -5138,12 +5189,7 @@ class EmailPasswordProvider {
|
|
|
5138
5189
|
// Email/Password auth is supported if we have the required config
|
|
5139
5190
|
return !!this.config.apiUrl;
|
|
5140
5191
|
}
|
|
5141
|
-
|
|
5142
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email/password authentication');
|
|
5143
|
-
}
|
|
5144
|
-
async unlinkAccount(_options) {
|
|
5145
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email/password authentication');
|
|
5146
|
-
}
|
|
5192
|
+
// linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
|
|
5147
5193
|
async revokeAccess(_token) {
|
|
5148
5194
|
// For email/password auth, revoking access means signing out
|
|
5149
5195
|
await this.signOut();
|
|
@@ -5155,11 +5201,15 @@ var emailPasswordProvider = /*#__PURE__*/Object.freeze({
|
|
|
5155
5201
|
EmailPasswordProvider: EmailPasswordProvider
|
|
5156
5202
|
});
|
|
5157
5203
|
|
|
5158
|
-
class BiometricProvider {
|
|
5159
|
-
|
|
5160
|
-
|
|
5204
|
+
class BiometricProvider extends BaseAuthProvider {
|
|
5205
|
+
get name() {
|
|
5206
|
+
return 'biometric';
|
|
5207
|
+
}
|
|
5208
|
+
constructor(input = {}) {
|
|
5209
|
+
super(resolveProviderConfig(exports.AuthProvider.BIOMETRIC, input));
|
|
5161
5210
|
this.biometricAuth = null;
|
|
5162
5211
|
this.cryptoKeyPromise = null;
|
|
5212
|
+
const config = this.options;
|
|
5163
5213
|
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);
|
|
5164
5214
|
this.storageKey =
|
|
5165
5215
|
config.storageKey || 'capacitor-auth-biometric-credentials';
|
|
@@ -5169,7 +5219,9 @@ class BiometricProvider {
|
|
|
5169
5219
|
async loadBiometricPlugin() {
|
|
5170
5220
|
try {
|
|
5171
5221
|
// Dynamic import to avoid errors if plugin not installed
|
|
5172
|
-
const { BiometricAuth } = await import(
|
|
5222
|
+
const { BiometricAuth } = await import(
|
|
5223
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- optional peer dep; module may be absent at build time
|
|
5224
|
+
'capacitor-biometric-authentication');
|
|
5173
5225
|
this.biometricAuth = BiometricAuth;
|
|
5174
5226
|
}
|
|
5175
5227
|
catch (_a) {
|
|
@@ -5177,7 +5229,6 @@ class BiometricProvider {
|
|
|
5177
5229
|
}
|
|
5178
5230
|
}
|
|
5179
5231
|
async signIn(_options) {
|
|
5180
|
-
var _a, _b, _c;
|
|
5181
5232
|
if (!this.biometricAuth) {
|
|
5182
5233
|
throw new AuthError(exports.AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, 'Biometric authentication plugin is not installed. Please install capacitor-biometric-authentication');
|
|
5183
5234
|
}
|
|
@@ -5232,18 +5283,22 @@ class BiometricProvider {
|
|
|
5232
5283
|
if (error instanceof AuthError)
|
|
5233
5284
|
throw error;
|
|
5234
5285
|
// Handle biometric errors
|
|
5235
|
-
|
|
5286
|
+
const errorCode = typeof error === 'object' && error !== null && 'code' in error
|
|
5287
|
+
? error.code
|
|
5288
|
+
: undefined;
|
|
5289
|
+
const errorMessage = getErrorMessage(error);
|
|
5290
|
+
if (errorCode === 'userCancel' || (errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('cancel'))) {
|
|
5236
5291
|
throw new AuthError(exports.AuthErrorCode.USER_CANCELLED, 'Authentication cancelled by user');
|
|
5237
5292
|
}
|
|
5238
|
-
else if (
|
|
5239
|
-
(
|
|
5293
|
+
else if (errorCode === 'biometryLockout' ||
|
|
5294
|
+
(errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('lockout'))) {
|
|
5240
5295
|
throw new AuthError(exports.AuthErrorCode.BIOMETRIC_LOCKOUT, 'Too many failed attempts. Biometry is locked.');
|
|
5241
5296
|
}
|
|
5242
|
-
else if (
|
|
5243
|
-
(
|
|
5297
|
+
else if (errorCode === 'biometryNotEnrolled' ||
|
|
5298
|
+
(errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.includes('enrolled'))) {
|
|
5244
5299
|
throw new AuthError(exports.AuthErrorCode.BIOMETRIC_NOT_ENROLLED, 'No biometric credentials are enrolled');
|
|
5245
5300
|
}
|
|
5246
|
-
throw new AuthError(exports.AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED,
|
|
5301
|
+
throw new AuthError(exports.AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, errorMessage || 'Biometric authentication failed');
|
|
5247
5302
|
}
|
|
5248
5303
|
}
|
|
5249
5304
|
async signOut() {
|
|
@@ -5443,9 +5498,7 @@ class BiometricProvider {
|
|
|
5443
5498
|
const result = await this.isAvailable();
|
|
5444
5499
|
return result.available;
|
|
5445
5500
|
}
|
|
5446
|
-
|
|
5447
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for biometric authentication');
|
|
5448
|
-
}
|
|
5501
|
+
// linkAccount inherits BaseAuthProvider's OPERATION_NOT_ALLOWED default (F-44).
|
|
5449
5502
|
async unlinkAccount(_options) {
|
|
5450
5503
|
// Unlinking biometric auth means clearing stored credentials
|
|
5451
5504
|
await this.clearStoredCredentials();
|
|
@@ -5722,12 +5775,17 @@ var linkedinProvider = /*#__PURE__*/Object.freeze({
|
|
|
5722
5775
|
LinkedInProvider: LinkedInProvider
|
|
5723
5776
|
});
|
|
5724
5777
|
|
|
5725
|
-
class UsernamePasswordProvider {
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5778
|
+
class UsernamePasswordProvider extends BaseAuthProvider {
|
|
5779
|
+
get name() {
|
|
5780
|
+
return 'username-password';
|
|
5781
|
+
}
|
|
5782
|
+
constructor(input) {
|
|
5783
|
+
super(resolveProviderConfig(exports.AuthProvider.USERNAME_PASSWORD, input));
|
|
5784
|
+
// currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
|
|
5785
|
+
// so username/password sessions stay in-memory exactly as before (no new storage persistence).
|
|
5729
5786
|
this.authToken = null;
|
|
5730
5787
|
this.refreshTokenValue = null;
|
|
5788
|
+
const config = this.options;
|
|
5731
5789
|
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);
|
|
5732
5790
|
}
|
|
5733
5791
|
async signIn(options) {
|
|
@@ -5799,7 +5857,7 @@ class UsernamePasswordProvider {
|
|
|
5799
5857
|
catch (error) {
|
|
5800
5858
|
if (error instanceof AuthError)
|
|
5801
5859
|
throw error;
|
|
5802
|
-
throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, error
|
|
5860
|
+
throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Failed to sign in with username and password');
|
|
5803
5861
|
}
|
|
5804
5862
|
}
|
|
5805
5863
|
async signUp(options) {
|
|
@@ -5891,7 +5949,7 @@ class UsernamePasswordProvider {
|
|
|
5891
5949
|
catch (error) {
|
|
5892
5950
|
if (error instanceof AuthError)
|
|
5893
5951
|
throw error;
|
|
5894
|
-
throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, error
|
|
5952
|
+
throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Failed to create account');
|
|
5895
5953
|
}
|
|
5896
5954
|
}
|
|
5897
5955
|
async signOut() {
|
|
@@ -5957,7 +6015,7 @@ class UsernamePasswordProvider {
|
|
|
5957
6015
|
catch (error) {
|
|
5958
6016
|
if (error instanceof AuthError)
|
|
5959
6017
|
throw error;
|
|
5960
|
-
throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
6018
|
+
throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Failed to refresh token');
|
|
5961
6019
|
}
|
|
5962
6020
|
}
|
|
5963
6021
|
async updatePassword(currentPassword, newPassword) {
|
|
@@ -5993,7 +6051,7 @@ class UsernamePasswordProvider {
|
|
|
5993
6051
|
catch (error) {
|
|
5994
6052
|
if (error instanceof AuthError)
|
|
5995
6053
|
throw error;
|
|
5996
|
-
throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, error
|
|
6054
|
+
throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, getErrorMessage(error) || 'Failed to update password');
|
|
5997
6055
|
}
|
|
5998
6056
|
}
|
|
5999
6057
|
async checkUsernameAvailability(username) {
|
|
@@ -6072,12 +6130,7 @@ class UsernamePasswordProvider {
|
|
|
6072
6130
|
// Username/Password auth is supported if we have the required config
|
|
6073
6131
|
return !!this.config.apiUrl;
|
|
6074
6132
|
}
|
|
6075
|
-
|
|
6076
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for username/password authentication');
|
|
6077
|
-
}
|
|
6078
|
-
async unlinkAccount(_options) {
|
|
6079
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for username/password authentication');
|
|
6080
|
-
}
|
|
6133
|
+
// linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
|
|
6081
6134
|
async revokeAccess(_token) {
|
|
6082
6135
|
// For username/password auth, revoking access means signing out
|
|
6083
6136
|
await this.signOut();
|
|
@@ -6089,15 +6142,18 @@ var usernamePasswordProvider = /*#__PURE__*/Object.freeze({
|
|
|
6089
6142
|
UsernamePasswordProvider: UsernamePasswordProvider
|
|
6090
6143
|
});
|
|
6091
6144
|
|
|
6092
|
-
class EmailCodeProvider {
|
|
6093
|
-
|
|
6094
|
-
|
|
6145
|
+
class EmailCodeProvider extends BaseAuthProvider {
|
|
6146
|
+
get name() {
|
|
6147
|
+
return 'email-code';
|
|
6148
|
+
}
|
|
6149
|
+
constructor(input) {
|
|
6150
|
+
super(resolveProviderConfig(exports.AuthProvider.EMAIL_CODE, input));
|
|
6095
6151
|
// Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
|
|
6096
6152
|
// page change between sending and verifying the code. Only non-secret metadata is stored —
|
|
6097
6153
|
// never the verification code itself (see PendingVerificationStore + F-11).
|
|
6098
6154
|
this.pendingVerifications = new PendingVerificationStore('email-code');
|
|
6099
6155
|
this.MAX_ATTEMPTS = 3;
|
|
6100
|
-
this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 },
|
|
6156
|
+
this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, this.options);
|
|
6101
6157
|
}
|
|
6102
6158
|
async signIn(options) {
|
|
6103
6159
|
if (!(options === null || options === void 0 ? void 0 : options.email)) {
|
|
@@ -6292,12 +6348,7 @@ class EmailCodeProvider {
|
|
|
6292
6348
|
async isSupported() {
|
|
6293
6349
|
return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
|
|
6294
6350
|
}
|
|
6295
|
-
|
|
6296
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email code authentication');
|
|
6297
|
-
}
|
|
6298
|
-
async unlinkAccount(_options) {
|
|
6299
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email code authentication');
|
|
6300
|
-
}
|
|
6351
|
+
// linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
|
|
6301
6352
|
async revokeAccess(_token) {
|
|
6302
6353
|
this.pendingVerifications.clear();
|
|
6303
6354
|
}
|
|
@@ -6342,11 +6393,15 @@ var emailCodeProvider = /*#__PURE__*/Object.freeze({
|
|
|
6342
6393
|
EmailCodeProvider: EmailCodeProvider
|
|
6343
6394
|
});
|
|
6344
6395
|
|
|
6345
|
-
class PhonePasswordProvider {
|
|
6346
|
-
|
|
6347
|
-
|
|
6396
|
+
class PhonePasswordProvider extends BaseAuthProvider {
|
|
6397
|
+
get name() {
|
|
6398
|
+
return 'phone-password';
|
|
6399
|
+
}
|
|
6400
|
+
constructor(input) {
|
|
6401
|
+
super(resolveProviderConfig(exports.AuthProvider.PHONE_PASSWORD, input));
|
|
6348
6402
|
this.pendingVerifications = new Map();
|
|
6349
|
-
|
|
6403
|
+
// currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
|
|
6404
|
+
// so phone/password sessions stay in-memory exactly as before (no new storage persistence).
|
|
6350
6405
|
this.storedAccessToken = null;
|
|
6351
6406
|
this.storedRefreshToken = null;
|
|
6352
6407
|
this.config = Object.assign({ countryCode: '+1', requirePhoneVerification: false, passwordStrength: {
|
|
@@ -6355,7 +6410,7 @@ class PhonePasswordProvider {
|
|
|
6355
6410
|
requireLowercase: true,
|
|
6356
6411
|
requireNumbers: true,
|
|
6357
6412
|
requireSpecialChars: false,
|
|
6358
|
-
} },
|
|
6413
|
+
} }, this.options);
|
|
6359
6414
|
}
|
|
6360
6415
|
async signIn(options) {
|
|
6361
6416
|
const credentials = options === null || options === void 0 ? void 0 : options.credentials;
|
|
@@ -6398,12 +6453,12 @@ class PhonePasswordProvider {
|
|
|
6398
6453
|
throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
|
|
6399
6454
|
}
|
|
6400
6455
|
const data = await response.json();
|
|
6401
|
-
return this.
|
|
6456
|
+
return this.buildAuthResult(data, phoneNumber);
|
|
6402
6457
|
}
|
|
6403
6458
|
catch (error) {
|
|
6404
6459
|
if (error instanceof AuthError)
|
|
6405
6460
|
throw error;
|
|
6406
|
-
throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, error
|
|
6461
|
+
throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, getErrorMessage(error) || 'Sign in failed');
|
|
6407
6462
|
}
|
|
6408
6463
|
}
|
|
6409
6464
|
async signUp(phoneNumber, password) {
|
|
@@ -6462,12 +6517,12 @@ class PhonePasswordProvider {
|
|
|
6462
6517
|
},
|
|
6463
6518
|
};
|
|
6464
6519
|
}
|
|
6465
|
-
return this.
|
|
6520
|
+
return this.buildAuthResult(data, phoneNumber, true);
|
|
6466
6521
|
}
|
|
6467
6522
|
catch (error) {
|
|
6468
6523
|
if (error instanceof AuthError)
|
|
6469
6524
|
throw error;
|
|
6470
|
-
throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, error
|
|
6525
|
+
throw new AuthError(exports.AuthErrorCode.SIGN_UP_FAILED, getErrorMessage(error) || 'Sign up failed');
|
|
6471
6526
|
}
|
|
6472
6527
|
}
|
|
6473
6528
|
async sendVerificationCode(phoneNumber) {
|
|
@@ -6530,12 +6585,12 @@ class PhonePasswordProvider {
|
|
|
6530
6585
|
}
|
|
6531
6586
|
const data = await response.json();
|
|
6532
6587
|
this.pendingVerifications.delete(phoneNumber);
|
|
6533
|
-
return this.
|
|
6588
|
+
return this.buildAuthResult(data, phoneNumber);
|
|
6534
6589
|
}
|
|
6535
6590
|
catch (error) {
|
|
6536
6591
|
if (error instanceof AuthError)
|
|
6537
6592
|
throw error;
|
|
6538
|
-
throw new AuthError(exports.AuthErrorCode.VERIFICATION_FAILED, error
|
|
6593
|
+
throw new AuthError(exports.AuthErrorCode.VERIFICATION_FAILED, getErrorMessage(error) || 'Phone verification failed');
|
|
6539
6594
|
}
|
|
6540
6595
|
}
|
|
6541
6596
|
async signOut() {
|
|
@@ -6591,7 +6646,7 @@ class PhonePasswordProvider {
|
|
|
6591
6646
|
catch (error) {
|
|
6592
6647
|
if (error instanceof AuthError)
|
|
6593
6648
|
throw error;
|
|
6594
|
-
throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, error
|
|
6649
|
+
throw new AuthError(exports.AuthErrorCode.TOKEN_REFRESH_FAILED, getErrorMessage(error) || 'Token refresh failed');
|
|
6595
6650
|
}
|
|
6596
6651
|
}
|
|
6597
6652
|
async initialize() {
|
|
@@ -6600,12 +6655,7 @@ class PhonePasswordProvider {
|
|
|
6600
6655
|
async isSupported() {
|
|
6601
6656
|
return !!(this.config.signInUrl && this.config.signUpUrl);
|
|
6602
6657
|
}
|
|
6603
|
-
|
|
6604
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for phone/password authentication');
|
|
6605
|
-
}
|
|
6606
|
-
async unlinkAccount(_options) {
|
|
6607
|
-
throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for phone/password authentication');
|
|
6608
|
-
}
|
|
6658
|
+
// linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
|
|
6609
6659
|
async revokeAccess(_token) {
|
|
6610
6660
|
await this.signOut();
|
|
6611
6661
|
}
|
|
@@ -6632,7 +6682,10 @@ class PhonePasswordProvider {
|
|
|
6632
6682
|
throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset');
|
|
6633
6683
|
}
|
|
6634
6684
|
}
|
|
6635
|
-
createAuthResult
|
|
6685
|
+
// Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
|
|
6686
|
+
// which has a different signature (this builds a phone-specific result from a backend payload).
|
|
6687
|
+
buildAuthResult(data, phoneNumber, isNewUser = false) {
|
|
6688
|
+
var _a, _b;
|
|
6636
6689
|
const user = {
|
|
6637
6690
|
uid: data.uid || this.generateUid(phoneNumber),
|
|
6638
6691
|
email: data.email || null,
|
|
@@ -6656,8 +6709,8 @@ class PhonePasswordProvider {
|
|
|
6656
6709
|
},
|
|
6657
6710
|
};
|
|
6658
6711
|
this.currentUser = user;
|
|
6659
|
-
this.storedAccessToken = data.accessToken;
|
|
6660
|
-
this.storedRefreshToken = data.refreshToken;
|
|
6712
|
+
this.storedAccessToken = (_a = data.accessToken) !== null && _a !== void 0 ? _a : null;
|
|
6713
|
+
this.storedRefreshToken = (_b = data.refreshToken) !== null && _b !== void 0 ? _b : null;
|
|
6661
6714
|
return {
|
|
6662
6715
|
user,
|
|
6663
6716
|
credential: {
|