capacitor-auth-manager 2.4.4 → 3.0.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.
Files changed (80) hide show
  1. package/AI-INTEGRATION-GUIDE.md +174 -0
  2. package/CHANGELOG.md +119 -0
  3. package/CapacitorAuthManager.podspec +3 -3
  4. package/README.md +91 -72
  5. package/android/build.gradle +17 -25
  6. package/android/consumer-rules.pro +2 -0
  7. package/android/proguard-rules.pro +5 -30
  8. package/android/src/main/AndroidManifest.xml +4 -9
  9. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthErrorCodes.java +32 -0
  10. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthException.java +34 -0
  11. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthStorage.java +46 -25
  12. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManager.java +54 -38
  13. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManagerPlugin.java +77 -54
  14. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/GoogleAuthProvider.java +171 -41
  15. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/ProviderFactory.java +5 -0
  16. package/dist/angular.cjs.js +421 -3376
  17. package/dist/core.cjs.js +589 -149
  18. package/dist/esm/angular/auth.guard.d.ts +1 -1
  19. package/dist/esm/angular/auth.module.d.ts +1 -1
  20. package/dist/esm/angular/auth.module.js +1 -1
  21. package/dist/esm/angular/auth.service.d.ts +2 -2
  22. package/dist/esm/angular/auth.service.js +1 -1
  23. package/dist/esm/angular/index.d.ts +4 -4
  24. package/dist/esm/angular/index.js +4 -4
  25. package/dist/esm/capacitor-plugin.d.ts +2 -3
  26. package/dist/esm/capacitor-plugin.js +14 -4
  27. package/dist/esm/core/auth-manager.d.ts +20 -2
  28. package/dist/esm/core/auth-manager.js +68 -12
  29. package/dist/esm/core/index.d.ts +5 -4
  30. package/dist/esm/core/index.js +5 -4
  31. package/dist/esm/core/provider-manifests.d.ts +1 -1
  32. package/dist/esm/core/provider-manifests.js +12 -13
  33. package/dist/esm/core/provider-registry.d.ts +8 -5
  34. package/dist/esm/core/provider-registry.js +41 -10
  35. package/dist/esm/core/types.d.ts +2 -2
  36. package/dist/esm/definitions.d.ts +26 -0
  37. package/dist/esm/index.d.ts +12 -12
  38. package/dist/esm/index.js +7 -7
  39. package/dist/esm/package.json +1 -0
  40. package/dist/esm/providers/base-provider.d.ts +7 -8
  41. package/dist/esm/providers/base-provider.js +7 -8
  42. package/dist/esm/providers/native/google-native-provider.d.ts +13 -2
  43. package/dist/esm/providers/native/google-native-provider.js +50 -6
  44. package/dist/esm/providers/oauth-provider.d.ts +2 -2
  45. package/dist/esm/providers/oauth-provider.js +3 -3
  46. package/dist/esm/providers/provider-factory.d.ts +5 -5
  47. package/dist/esm/providers/provider-factory.js +2 -2
  48. package/dist/esm/providers/web/google-provider.d.ts +74 -18
  49. package/dist/esm/providers/web/google-provider.js +391 -117
  50. package/dist/esm/providers/web/index.d.ts +1 -1
  51. package/dist/esm/providers/web/index.js +1 -1
  52. package/dist/esm/react/hooks.d.ts +2 -2
  53. package/dist/esm/react/hooks.js +2 -2
  54. package/dist/esm/react/index.d.ts +3 -3
  55. package/dist/esm/react/index.js +3 -3
  56. package/dist/esm/react/types.d.ts +1 -1
  57. package/dist/esm/utils/auth-error.d.ts +1 -1
  58. package/dist/esm/utils/auth-error.js +1 -1
  59. package/dist/esm/utils/event-emitter.d.ts +1 -1
  60. package/dist/esm/utils/event-emitter.js +1 -1
  61. package/dist/esm/utils/pending-verification-store.js +1 -1
  62. package/dist/esm/utils/storage.d.ts +2 -2
  63. package/dist/esm/utils/storage.js +31 -7
  64. package/dist/esm/vue/composables.d.ts +2 -2
  65. package/dist/esm/vue/composables.js +1 -1
  66. package/dist/esm/vue/index.d.ts +2 -2
  67. package/dist/esm/vue/index.js +2 -2
  68. package/dist/esm/web.d.ts +1 -1
  69. package/dist/esm/web.js +6 -6
  70. package/dist/plugin.cjs.js +291 -2771
  71. package/dist/plugin.js +585 -147
  72. package/dist/providers-web.cjs.js +1317 -0
  73. package/dist/react.cjs.js +310 -3265
  74. package/dist/vue.cjs.js +266 -3221
  75. package/ios/Plugin/AuthStorage.swift +3 -1
  76. package/ios/Plugin/GoogleAuthProvider.swift +7 -4
  77. package/ios/Plugin/Models.swift +28 -0
  78. package/ios/Plugin/Plugin.swift +64 -40
  79. package/package.json +55 -33
  80. package/scripts/configure.js +71 -325
@@ -1,6 +1,6 @@
1
1
  import { CanActivate, CanActivateChild, CanLoad, Router, UrlTree, ActivatedRouteSnapshot, RouterStateSnapshot, Route, UrlSegment } from '@angular/router';
2
2
  import { Observable } from 'rxjs';
3
- import { AuthService } from './auth.service';
3
+ import { AuthService } from './auth.service.js';
4
4
  export declare class AuthGuard implements CanActivate, CanActivateChild, CanLoad {
5
5
  private authService;
6
6
  private router;
@@ -1,5 +1,5 @@
1
1
  import { ModuleWithProviders, InjectionToken } from '@angular/core';
2
- import type { ProviderOptions } from '../definitions';
2
+ import type { ProviderOptions } from '../definitions.js';
3
3
  export interface AuthModuleConfig {
4
4
  providers?: Record<string, ProviderOptions>;
5
5
  persistence?: 'local' | 'session' | 'memory';
@@ -1,7 +1,7 @@
1
1
  import { __esDecorate, __runInitializers, __setFunctionName } from "tslib";
2
2
  import { NgModule, InjectionToken, inject, } from '@angular/core';
3
3
  import { CommonModule } from '@angular/common';
4
- import { AuthService, AuthProviderFactory } from './auth.service';
4
+ import { AuthService, AuthProviderFactory } from './auth.service.js';
5
5
  /**
6
6
  * DI token carrying the config passed to {@link AuthModule.forRoot}. Typed `InjectionToken`
7
7
  * (string tokens aren't assignable to the typed `inject()` overload in Angular's current API).
@@ -1,7 +1,7 @@
1
1
  import { OnDestroy } from '@angular/core';
2
2
  import { Observable } from 'rxjs';
3
- import type { AuthState, AuthManagerConfig } from '../core/types';
4
- import type { AuthUser, AuthResult, SignInOptions, SignOutOptions, LinkAccountOptions, UnlinkAccountOptions, GetIdTokenOptions, UpdateProfileOptions, DeleteAccountOptions } from '../definitions';
3
+ import type { AuthState, AuthManagerConfig } from '../core/types.js';
4
+ import type { AuthUser, AuthResult, SignInOptions, SignOutOptions, LinkAccountOptions, UnlinkAccountOptions, GetIdTokenOptions, UpdateProfileOptions, DeleteAccountOptions } from '../definitions.js';
5
5
  export declare class AuthService implements OnDestroy {
6
6
  private stateSubject;
7
7
  private unsubscribe;
@@ -2,7 +2,7 @@ import { __esDecorate, __runInitializers, __setFunctionName } from "tslib";
2
2
  import { Injectable } from '@angular/core';
3
3
  import { BehaviorSubject, from, throwError } from 'rxjs';
4
4
  import { map, catchError } from 'rxjs/operators';
5
- import { auth } from '../core/auth-manager';
5
+ import { auth } from '../core/auth-manager.js';
6
6
  let AuthService = (() => {
7
7
  let _classDecorators = [Injectable({
8
8
  providedIn: 'root',
@@ -1,4 +1,4 @@
1
- export { AuthService, AuthProviderService, AuthProviderFactory, } from './auth.service';
2
- export { AuthModule, AuthModuleConfig, AUTH_CONFIG } from './auth.module';
3
- export { AuthGuard, NoAuthGuard } from './auth.guard';
4
- export { AuthProvider, AuthErrorCode } from '../definitions';
1
+ export { AuthService, AuthProviderService, AuthProviderFactory, } from './auth.service.js';
2
+ export { AuthModule, AuthModuleConfig, AUTH_CONFIG } from './auth.module.js';
3
+ export { AuthGuard, NoAuthGuard } from './auth.guard.js';
4
+ export { AuthProvider, AuthErrorCode } from '../definitions.js';
@@ -1,7 +1,7 @@
1
- export { AuthService, AuthProviderService, AuthProviderFactory, } from './auth.service';
2
- export { AuthModule, AUTH_CONFIG } from './auth.module';
3
- export { AuthGuard, NoAuthGuard } from './auth.guard';
1
+ export { AuthService, AuthProviderService, AuthProviderFactory, } from './auth.service.js';
2
+ export { AuthModule, AUTH_CONFIG } from './auth.module.js';
3
+ export { AuthGuard, NoAuthGuard } from './auth.guard.js';
4
4
  // Re-export the AuthProvider enum (+ error codes) so consumers get `authService.signIn(AuthProvider.GOOGLE)`
5
5
  // with a single import. Using the enum is the recommended, typo-safe way to name a provider — plain
6
6
  // strings like 'google' still work.
7
- export { AuthProvider, AuthErrorCode } from '../definitions';
7
+ export { AuthProvider, AuthErrorCode } from '../definitions.js';
@@ -1,3 +1,2 @@
1
- import type { CapacitorAuthManagerPlugin } from './definitions';
2
- declare const CapacitorAuthManager: CapacitorAuthManagerPlugin;
3
- export { CapacitorAuthManager };
1
+ import type { CapacitorAuthManagerPlugin } from './definitions.js';
2
+ export declare const CapacitorAuthManager: CapacitorAuthManagerPlugin;
@@ -1,6 +1,16 @@
1
1
  import { registerPlugin } from '@capacitor/core';
2
- // This provides backward compatibility for users who still want to use the Capacitor plugin interface
3
- const CapacitorAuthManager = registerPlugin('CapacitorAuthManager', {
4
- web: () => import('./web').then((m) => new m.CapacitorAuthManagerWeb()),
2
+ let plugin = null;
3
+ function getPlugin() {
4
+ plugin !== null && plugin !== void 0 ? plugin : (plugin = registerPlugin('CapacitorAuthManager', {
5
+ web: () => import('./web.js').then((m) => new m.CapacitorAuthManagerWeb()),
6
+ }));
7
+ return plugin;
8
+ }
9
+ // Importing the package never registers a native plugin or touches a browser global.
10
+ export const CapacitorAuthManager = new Proxy({}, {
11
+ get(_target, property) {
12
+ const target = getPlugin();
13
+ const value = Reflect.get(target, property, target);
14
+ return typeof value === 'function' ? value.bind(target) : value;
15
+ },
5
16
  });
6
- export { CapacitorAuthManager };
@@ -1,5 +1,5 @@
1
- import type { AuthManagerConfig, AuthState, AuthStateListener } from './types';
2
- import type { AuthUser, AuthResult, SignInOptions, SignOutOptions, LinkAccountOptions, UnlinkAccountOptions, GetIdTokenOptions, UpdateProfileOptions, DeleteAccountOptions } from '../definitions';
1
+ import type { AuthManagerConfig, AuthState, AuthStateListener } from './types.js';
2
+ import type { AuthUser, AuthResult, SignInOptions, SignOutOptions, LinkAccountOptions, UnlinkAccountOptions, GetIdTokenOptions, UpdateProfileOptions, DeleteAccountOptions } from '../definitions.js';
3
3
  declare class AuthManagerCore {
4
4
  private state;
5
5
  private stateEmitter;
@@ -10,10 +10,13 @@ declare class AuthManagerCore {
10
10
  private tokenRefreshTimers;
11
11
  private initPromise;
12
12
  private currentPersistence;
13
+ private sessionRevision;
13
14
  constructor();
14
15
  initialize(config?: AuthManagerConfig): Promise<void>;
15
16
  configure(config: AuthManagerConfig): void;
16
17
  signIn(providerOrOptions: string | SignInOptions): Promise<AuthResult>;
18
+ /** Load the provider SDK before a user gesture, without opening a sign-in prompt. */
19
+ prepare(provider: string): Promise<void>;
17
20
  signOut(options?: SignOutOptions): Promise<void>;
18
21
  getCurrentUser(): AuthUser | null;
19
22
  getAuthState(): AuthState;
@@ -82,6 +85,7 @@ declare class AuthManagerCore {
82
85
  */
83
86
  private sanitizeCredentialForStorage;
84
87
  private restoreAuthState;
88
+ private assertIdle;
85
89
  private setupTokenRefresh;
86
90
  /**
87
91
  * Schedules the refresh, clamping the delay to the 32-bit `setTimeout` ceiling
@@ -95,5 +99,19 @@ declare class AuthManagerCore {
95
99
  private clearAllTokenRefresh;
96
100
  dispose(): void;
97
101
  }
102
+ /**
103
+ * Returns the process-wide auth manager, constructing it on first call.
104
+ *
105
+ * The singleton is created lazily on purpose (ISSUE-002): constructing it eagerly at module scope
106
+ * built a `WebStorage` that read `window.localStorage` while the module was being evaluated, which
107
+ * crashed any import under Node / SSR and made `"sideEffects": false` untrue. Nothing touches the
108
+ * browser until the first real use.
109
+ */
110
+ export declare function getAuth(): AuthManagerCore;
111
+ /**
112
+ * The shared auth manager. Every property access is forwarded to the lazily-created instance, so
113
+ * `import { auth } from 'capacitor-auth-manager'` keeps working unchanged while importing the
114
+ * package has no side effects.
115
+ */
98
116
  export declare const auth: AuthManagerCore;
99
117
  export type { AuthManagerCore };
@@ -1,9 +1,9 @@
1
- import { EventEmitter } from '../utils/event-emitter';
2
- import { Logger } from '../utils/logger';
3
- import { WebStorage } from '../utils/storage';
4
- import { AuthError } from '../utils/auth-error';
5
- import { ProviderRegistry } from './provider-registry';
6
- import { AuthProvider, AuthErrorCode, AuthPersistence } from '../definitions';
1
+ import { EventEmitter } from '../utils/event-emitter.js';
2
+ import { Logger } from '../utils/logger.js';
3
+ import { WebStorage } from '../utils/storage.js';
4
+ import { AuthError } from '../utils/auth-error.js';
5
+ import { ProviderRegistry } from './provider-registry.js';
6
+ import { AuthProvider, AuthErrorCode, AuthPersistence, } from '../definitions.js';
7
7
  /**
8
8
  * Maps the config's persistence literal to the {@link AuthPersistence} enum WebStorage expects.
9
9
  * Critically, `'memory'` maps to {@link AuthPersistence.NONE} (`'none'`) — previously the literal
@@ -34,6 +34,7 @@ class AuthManagerCore {
34
34
  this.isInitialized = false;
35
35
  this.tokenRefreshTimers = new Map();
36
36
  this.initPromise = null;
37
+ this.sessionRevision = 0;
37
38
  this.logger = new Logger({
38
39
  enableLogging: false,
39
40
  logLevel: 'info',
@@ -111,6 +112,8 @@ class AuthManagerCore {
111
112
  async signIn(providerOrOptions) {
112
113
  var _a, _b, _c;
113
114
  await this.ensureInitialized();
115
+ this.assertIdle();
116
+ this.sessionRevision++;
114
117
  let providerName;
115
118
  let signInOptions = {};
116
119
  if (typeof providerOrOptions === 'string') {
@@ -173,9 +176,16 @@ class AuthManagerCore {
173
176
  throw AuthError.fromError(error);
174
177
  }
175
178
  }
179
+ /** Load the provider SDK before a user gesture, without opening a sign-in prompt. */
180
+ async prepare(provider) {
181
+ await this.ensureInitialized();
182
+ await this.resolveProvider(provider);
183
+ }
176
184
  async signOut(options) {
177
185
  var _a;
178
186
  await this.ensureInitialized();
187
+ this.assertIdle();
188
+ this.sessionRevision++;
179
189
  const provider = (options === null || options === void 0 ? void 0 : options.provider) || this.state.provider;
180
190
  if (!provider) {
181
191
  this.logger.warn('No active auth session to sign out from');
@@ -391,7 +401,8 @@ class AuthManagerCore {
391
401
  throw new AuthError(AuthErrorCode.NO_AUTH_SESSION, 'No authenticated user to delete');
392
402
  }
393
403
  const provider = await this.resolveProvider(targetProvider);
394
- const deleteFn = provider.deleteAccount;
404
+ const deleteFn = provider
405
+ .deleteAccount;
395
406
  if (typeof deleteFn !== 'function') {
396
407
  throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `deleteAccount not supported for ${targetProvider}`);
397
408
  }
@@ -445,7 +456,11 @@ class AuthManagerCore {
445
456
  }
446
457
  }
447
458
  getProviderDeps() {
448
- return { storage: this.storage, logger: this.logger };
459
+ return {
460
+ storage: this.storage,
461
+ logger: this.logger,
462
+ persistence: toAuthPersistence(this.config.persistence),
463
+ };
449
464
  }
450
465
  /**
451
466
  * Resolves a provider instance through the registry, threading the configured options and the
@@ -479,6 +494,7 @@ class AuthManagerCore {
479
494
  }
480
495
  async restoreAuthState() {
481
496
  var _a, _b;
497
+ const revision = this.sessionRevision;
482
498
  try {
483
499
  const stored = await this.storage.get('auth_state');
484
500
  if ((stored === null || stored === void 0 ? void 0 : stored.user) && (stored === null || stored === void 0 ? void 0 : stored.provider)) {
@@ -488,7 +504,7 @@ class AuthManagerCore {
488
504
  try {
489
505
  const provider = await ProviderRegistry.getProvider(stored.provider, providerConfig, this.getProviderDeps());
490
506
  const currentUser = await provider.getCurrentUser();
491
- if (currentUser) {
507
+ if (currentUser && revision === this.sessionRevision) {
492
508
  this.updateState({
493
509
  user: currentUser,
494
510
  isAuthenticated: true,
@@ -503,7 +519,8 @@ class AuthManagerCore {
503
519
  }
504
520
  catch (error) {
505
521
  this.logger.warn('Failed to restore auth session:', error);
506
- await this.storage.remove('auth_state');
522
+ if (revision === this.sessionRevision)
523
+ await this.storage.remove('auth_state');
507
524
  }
508
525
  }
509
526
  }
@@ -512,6 +529,11 @@ class AuthManagerCore {
512
529
  this.logger.error('Failed to restore auth state:', error);
513
530
  }
514
531
  }
532
+ assertIdle() {
533
+ if (this.state.isLoading) {
534
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'An authentication operation is already in progress');
535
+ }
536
+ }
515
537
  setupTokenRefresh(provider, credential) {
516
538
  this.clearTokenRefresh(provider);
517
539
  if (!credential.expiresAt || !credential.refreshToken) {
@@ -565,6 +587,7 @@ class AuthManagerCore {
565
587
  this.tokenRefreshTimers.clear();
566
588
  }
567
589
  dispose() {
590
+ this.sessionRevision++;
568
591
  // Clear all timers
569
592
  for (const timer of this.tokenRefreshTimers.values()) {
570
593
  clearTimeout(timer);
@@ -576,5 +599,38 @@ class AuthManagerCore {
576
599
  this.stateEmitter.clear();
577
600
  }
578
601
  }
579
- // Create singleton instance
580
- export const auth = new AuthManagerCore();
602
+ let instance = null;
603
+ /**
604
+ * Returns the process-wide auth manager, constructing it on first call.
605
+ *
606
+ * The singleton is created lazily on purpose (ISSUE-002): constructing it eagerly at module scope
607
+ * built a `WebStorage` that read `window.localStorage` while the module was being evaluated, which
608
+ * crashed any import under Node / SSR and made `"sideEffects": false` untrue. Nothing touches the
609
+ * browser until the first real use.
610
+ */
611
+ export function getAuth() {
612
+ if (!instance) {
613
+ instance = new AuthManagerCore();
614
+ }
615
+ return instance;
616
+ }
617
+ /**
618
+ * The shared auth manager. Every property access is forwarded to the lazily-created instance, so
619
+ * `import { auth } from 'capacitor-auth-manager'` keeps working unchanged while importing the
620
+ * package has no side effects.
621
+ */
622
+ export const auth = new Proxy({}, {
623
+ get(_target, property) {
624
+ const target = getAuth();
625
+ const value = Reflect.get(target, property, target);
626
+ return typeof value === 'function'
627
+ ? value.bind(target)
628
+ : value;
629
+ },
630
+ set(_target, property, value) {
631
+ return Reflect.set(getAuth(), property, value);
632
+ },
633
+ has(_target, property) {
634
+ return Reflect.has(getAuth(), property);
635
+ },
636
+ });
@@ -1,4 +1,5 @@
1
- export * from './auth-manager';
2
- export * from './types';
3
- export * from './platform';
4
- export * from './provider-registry';
1
+ export * from './auth-manager.js';
2
+ export * from './types.js';
3
+ export * from './platform.js';
4
+ export * from './provider-registry.js';
5
+ export { CapacitorAuthManager } from '../capacitor-plugin.js';
@@ -1,4 +1,5 @@
1
- export * from './auth-manager';
2
- export * from './types';
3
- export * from './platform';
4
- export * from './provider-registry';
1
+ export * from './auth-manager.js';
2
+ export * from './types.js';
3
+ export * from './platform.js';
4
+ export * from './provider-registry.js';
5
+ export { CapacitorAuthManager } from '../capacitor-plugin.js';
@@ -1,4 +1,4 @@
1
- import type { ProviderManifest } from './types';
1
+ import type { ProviderManifest } from './types.js';
2
2
  /**
3
3
  * Built-in provider manifests (display metadata + human-readable setup instructions).
4
4
  *
@@ -9,28 +9,27 @@ export const BUILT_IN_PROVIDER_MANIFESTS = [
9
9
  {
10
10
  name: 'google',
11
11
  displayName: 'Google',
12
- packageName: '@google/gsi',
13
12
  setupInstructions: `
14
- To use Google authentication, you need to:
13
+ To use Google authentication:
15
14
 
16
- 1. Install the Google Sign-In SDK:
17
- npm install @google/gsi
15
+ 1. Create (or reuse) an OAuth 2.0 **Web** client in Google Cloud Console — Firebase creates one for you
16
+ when you enable the Google sign-in provider. Add your site origins (including your dev server, e.g.
17
+ http://localhost:5931) under "Authorized JavaScript origins".
18
18
 
19
- 2. Configure your Google OAuth client:
20
- - Go to https://console.cloud.google.com/
21
- - Create or select a project
22
- - Enable Google Sign-In API
23
- - Create OAuth 2.0 credentials
24
- - Add authorized JavaScript origins
25
-
26
- 3. Configure the provider:
19
+ 2. Configure the provider (no extra npm package is needed — the Google Identity Services script is
20
+ loaded on demand on web; the native SDKs ship with the plugin):
27
21
  auth.configure({
28
22
  providers: {
29
23
  google: {
30
- clientId: 'YOUR_CLIENT_ID'
24
+ clientId: 'YOUR_WEB_CLIENT_ID', // web + Android serverClientId fallback
25
+ serverClientId: 'YOUR_WEB_CLIENT_ID', // Android
26
+ iosClientId: 'YOUR_IOS_CLIENT_ID', // iOS (or GIDClientID in Info.plist)
31
27
  }
32
28
  }
33
29
  })
30
+
31
+ 3. Android: register your signing key's SHA-1 in Firebase / Google Cloud. iOS: add the reversed
32
+ client id as a URL scheme.
34
33
  `,
35
34
  platforms: ['web', 'ios', 'android'],
36
35
  configSchema: {
@@ -1,8 +1,8 @@
1
- import type { AuthProviderInterface, ProviderManifest } from './types';
2
- import { AuthPersistence } from '../definitions';
3
- import type { ProviderOptions } from '../definitions';
4
- import type { StorageInterface } from '../utils/storage';
5
- import { Logger } from '../utils/logger';
1
+ import type { AuthProviderInterface, ProviderManifest } from './types.js';
2
+ import { AuthPersistence } from '../definitions.js';
3
+ import type { ProviderOptions } from '../definitions.js';
4
+ import type { StorageInterface } from '../utils/storage.js';
5
+ import { Logger } from '../utils/logger.js';
6
6
  export interface ProviderLoader {
7
7
  (): Promise<{
8
8
  default: new (config?: unknown) => AuthProviderInterface;
@@ -21,6 +21,8 @@ export interface ProviderDeps {
21
21
  }
22
22
  export declare class ProviderRegistry {
23
23
  private static providers;
24
+ private static pending;
25
+ private static generation;
24
26
  private static loaders;
25
27
  private static manifests;
26
28
  /** Providers constructed with their raw options object (not a BaseProviderConfig wrapper). */
@@ -39,6 +41,7 @@ export declare class ProviderRegistry {
39
41
  static getManifest(name: string): ProviderManifest | undefined;
40
42
  static canonicalName(name: string): string;
41
43
  static getProvider(name: string, options?: ProviderOptions, deps?: ProviderDeps): Promise<AuthProviderInterface>;
44
+ private static createProvider;
42
45
  static clearProvider(name: string): void;
43
46
  static clearAll(): void;
44
47
  static getAvailableProviders(): string[];
@@ -1,11 +1,11 @@
1
1
  var _a;
2
- import { PlatformDetector } from './platform';
3
- import { AuthPersistence, AuthErrorCode } from '../definitions';
4
- import { AuthError } from '../utils/auth-error';
5
- import { WebStorage } from '../utils/storage';
6
- import { Logger } from '../utils/logger';
7
- import { getErrorMessage } from '../utils/error-message';
8
- import { BUILT_IN_PROVIDER_MANIFESTS } from './provider-manifests';
2
+ import { PlatformDetector } from './platform.js';
3
+ import { AuthPersistence, AuthErrorCode, } from '../definitions.js';
4
+ import { AuthError } from '../utils/auth-error.js';
5
+ import { WebStorage } from '../utils/storage.js';
6
+ import { Logger } from '../utils/logger.js';
7
+ import { getErrorMessage } from '../utils/error-message.js';
8
+ import { BUILT_IN_PROVIDER_MANIFESTS } from './provider-manifests.js';
9
9
  export class ProviderRegistry {
10
10
  static registerManifest(manifest) {
11
11
  this.manifests.set(manifest.name, manifest);
@@ -21,7 +21,26 @@ export class ProviderRegistry {
21
21
  return (_b = this.NAME_ALIASES[name]) !== null && _b !== void 0 ? _b : name;
22
22
  }
23
23
  static async getProvider(name, options, deps) {
24
- var _b, _c;
24
+ const key = this.canonicalName(name);
25
+ const existing = this.providers.get(key);
26
+ if (existing)
27
+ return existing;
28
+ const pending = this.pending.get(key);
29
+ if (pending)
30
+ return pending;
31
+ const promise = this.createProvider(name, options, deps);
32
+ this.pending.set(key, promise);
33
+ try {
34
+ return await promise;
35
+ }
36
+ finally {
37
+ if (this.pending.get(key) === promise)
38
+ this.pending.delete(key);
39
+ }
40
+ }
41
+ static async createProvider(name, options, deps) {
42
+ var _b, _c, _d;
43
+ const generation = this.generation;
25
44
  const key = this.canonicalName(name);
26
45
  // Check if already loaded
27
46
  const existing = this.providers.get(key);
@@ -79,6 +98,10 @@ export class ProviderRegistry {
79
98
  if (provider.initialize) {
80
99
  await provider.initialize();
81
100
  }
101
+ if (generation !== this.generation) {
102
+ (_d = provider.dispose) === null || _d === void 0 ? void 0 : _d.call(provider);
103
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Provider configuration changed during initialization');
104
+ }
82
105
  // Cache the provider under its canonical key
83
106
  this.providers.set(key, provider);
84
107
  return provider;
@@ -100,7 +123,9 @@ export class ProviderRegistry {
100
123
  }
101
124
  }
102
125
  static clearProvider(name) {
126
+ this.generation++;
103
127
  const key = this.canonicalName(name);
128
+ this.pending.delete(key);
104
129
  const provider = this.providers.get(key);
105
130
  if (provider === null || provider === void 0 ? void 0 : provider.dispose) {
106
131
  provider.dispose();
@@ -108,6 +133,8 @@ export class ProviderRegistry {
108
133
  this.providers.delete(key);
109
134
  }
110
135
  static clearAll() {
136
+ this.generation++;
137
+ this.pending.clear();
111
138
  for (const [, provider] of this.providers) {
112
139
  if (provider.dispose) {
113
140
  provider.dispose();
@@ -122,6 +149,8 @@ export class ProviderRegistry {
122
149
  const platform = PlatformDetector.getPlatform();
123
150
  const supported = [];
124
151
  for (const [name, manifest] of this.manifests) {
152
+ if (!this.loaders.has(name))
153
+ continue;
125
154
  if (!manifest.platforms ||
126
155
  manifest.platforms.includes(platform.platform)) {
127
156
  supported.push(name);
@@ -132,6 +161,8 @@ export class ProviderRegistry {
132
161
  }
133
162
  _a = ProviderRegistry;
134
163
  ProviderRegistry.providers = new Map();
164
+ ProviderRegistry.pending = new Map();
165
+ ProviderRegistry.generation = 0;
135
166
  ProviderRegistry.loaders = new Map();
136
167
  ProviderRegistry.manifests = new Map();
137
168
  /** Providers constructed with their raw options object (not a BaseProviderConfig wrapper). */
@@ -187,10 +218,10 @@ ProviderRegistry.RECOGNIZED_PROVIDERS = new Set([
187
218
  _a.registerLoader('google', () => {
188
219
  const { platform } = PlatformDetector.getPlatform();
189
220
  return platform === 'ios' || platform === 'android'
190
- ? import('../providers/native/google-native-provider').then((m) => ({
221
+ ? import('../providers/native/google-native-provider.js').then((m) => ({
191
222
  default: m.GoogleNativeProvider,
192
223
  }))
193
- : import('../providers/web/google-provider').then((m) => ({
224
+ : import('../providers/web/google-provider.js').then((m) => ({
194
225
  default: m.GoogleAuthProviderWeb,
195
226
  }));
196
227
  });
@@ -1,5 +1,5 @@
1
- import type { AuthUser, AuthResult, SignInOptions, SignOutOptions, RefreshTokenOptions, LinkAccountOptions, UnlinkAccountOptions, ProviderOptions } from '../definitions';
2
- import type { StorageInterface } from '../utils/storage';
1
+ import type { AuthUser, AuthResult, SignInOptions, SignOutOptions, RefreshTokenOptions, LinkAccountOptions, UnlinkAccountOptions, ProviderOptions } from '../definitions.js';
2
+ import type { StorageInterface } from '../utils/storage.js';
3
3
  export interface AuthManagerConfig {
4
4
  providers?: Record<string, ProviderOptions>;
5
5
  persistence?: 'local' | 'session' | 'memory';
@@ -109,7 +109,29 @@ export interface GoogleAuthOptions {
109
109
  autoSelectEnabled?: boolean;
110
110
  /** GIS web: a per-request nonce (also forwarded to Android). Validated against the returned idToken. */
111
111
  nonce?: string;
112
+ /**
113
+ * Web only — which Google Identity Services flow `signIn()` uses.
114
+ * - `'auto'` (default): try One-Tap / FedCM first; if the browser does not display it (cooldown,
115
+ * FedCM opt-out, third-party-cookie settings) fall back to the OAuth2 popup.
116
+ * - `'one-tap'`: One-Tap only; a suppressed prompt rejects with `POPUP_BLOCKED`.
117
+ * - `'popup'`: the OAuth2 token popup only — deterministic, works from any click handler.
118
+ * One-Tap yields an `idToken`; the popup yields an `accessToken` (plus the Google profile). Both are
119
+ * accepted by Firebase: `GoogleAuthProvider.credential(idToken ?? null, accessToken)`.
120
+ */
121
+ webFlow?: GoogleWebFlow;
122
+ /**
123
+ * Android only — which Credential Manager flow `signIn()` uses.
124
+ * - `'auto'` (default): the Google account bottom sheet; if no credential is available fall back to
125
+ * the explicit "Sign in with Google" button flow, which can add an account.
126
+ * - `'bottom-sheet'`: bottom sheet only.
127
+ * - `'button'`: the "Sign in with Google" button flow only.
128
+ */
129
+ androidFlow?: GoogleAndroidFlow;
112
130
  }
131
+ /** Web sign-in flow selector for the Google provider. See {@link GoogleAuthOptions.webFlow}. */
132
+ export type GoogleWebFlow = 'auto' | 'one-tap' | 'popup';
133
+ /** Android sign-in flow selector for the Google provider. See {@link GoogleAuthOptions.androidFlow}. */
134
+ export type GoogleAndroidFlow = 'auto' | 'bottom-sheet' | 'button';
113
135
  export interface AppleAuthOptions {
114
136
  clientId: string;
115
137
  redirectUri: string;
@@ -367,6 +389,10 @@ export type SignInProviderOptions = {
367
389
  state?: string;
368
390
  nonce?: string;
369
391
  pkceEnabled?: boolean;
392
+ /** Google web: per-call override of {@link GoogleAuthOptions.webFlow}. */
393
+ webFlow?: GoogleWebFlow;
394
+ /** Google Android: per-call override of {@link GoogleAuthOptions.androidFlow}. */
395
+ androidFlow?: GoogleAndroidFlow;
370
396
  };
371
397
  export interface SignOutOptions {
372
398
  provider?: AuthProvider;
@@ -1,12 +1,12 @@
1
- export { auth } from './core/auth-manager';
2
- export type { AuthManagerConfig, AuthState, AuthStateListener, AuthProviderInterface, ProviderManifest, } from './core/types';
3
- export { AuthUser, UserInfo, UserMetadata, AuthResult, AuthCredential, AdditionalUserInfo, SignInOptions, SignOutOptions, AuthProvider, AuthErrorCode, AuthPersistence, ProviderOptions, RefreshTokenOptions, LinkAccountOptions, UnlinkAccountOptions, AuthStateChangeCallback, GetIdTokenOptions, UpdateProfileOptions, BiometricAuthOptions, BiometricType, AppleAuthScope, PasswordStrengthRequirements, UsernameRequirements, AuthCredentials, } from './definitions';
4
- export { PlatformDetector } from './core/platform';
5
- export type { Platform, PlatformInfo } from './core/platform';
6
- export { WebStorage, CapacitorPreferencesStorage } from './utils/storage';
7
- export type { StorageInterface } from './utils/storage';
8
- export { AuthError, isAuthError } from './utils/auth-error';
9
- export { Logger, defaultLogger } from './utils/logger';
10
- export type { LogLevel, LoggerConfig } from './utils/logger';
11
- export { CapacitorAuthManager } from './capacitor-plugin';
12
- export type { CapacitorAuthManagerPlugin } from './definitions';
1
+ export { auth } from './core/auth-manager.js';
2
+ export type { AuthManagerConfig, AuthState, AuthStateListener, AuthProviderInterface, ProviderManifest, } from './core/types.js';
3
+ export { AuthUser, UserInfo, UserMetadata, AuthResult, AuthCredential, AdditionalUserInfo, SignInOptions, SignOutOptions, AuthProvider, AuthErrorCode, AuthPersistence, ProviderOptions, RefreshTokenOptions, LinkAccountOptions, UnlinkAccountOptions, AuthStateChangeCallback, GetIdTokenOptions, UpdateProfileOptions, BiometricAuthOptions, BiometricType, AppleAuthScope, PasswordStrengthRequirements, UsernameRequirements, AuthCredentials, GoogleAuthOptions, GoogleWebFlow, GoogleAndroidFlow, DeleteAccountOptions, } from './definitions.js';
4
+ export { PlatformDetector } from './core/platform.js';
5
+ export type { Platform, PlatformInfo } from './core/platform.js';
6
+ export { WebStorage, CapacitorPreferencesStorage } from './utils/storage.js';
7
+ export type { StorageInterface } from './utils/storage.js';
8
+ export { AuthError, isAuthError } from './utils/auth-error.js';
9
+ export { Logger, defaultLogger } from './utils/logger.js';
10
+ export type { LogLevel, LoggerConfig } from './utils/logger.js';
11
+ export { CapacitorAuthManager } from './capacitor-plugin.js';
12
+ export type { CapacitorAuthManagerPlugin } from './definitions.js';
package/dist/esm/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  // Main export - the singleton auth instance
2
- export { auth } from './core/auth-manager';
2
+ export { auth } from './core/auth-manager.js';
3
3
  // Re-export shared types from definitions (these are used by both old and new API)
4
- export { AuthProvider, AuthErrorCode, AuthPersistence, BiometricType, AppleAuthScope, } from './definitions';
5
- export { PlatformDetector } from './core/platform';
4
+ export { AuthProvider, AuthErrorCode, AuthPersistence, BiometricType, AppleAuthScope, } from './definitions.js';
5
+ export { PlatformDetector } from './core/platform.js';
6
6
  // Storage backends. Inject a secure implementation on native via
7
7
  // auth.configure({ storage: new CapacitorPreferencesStorage() }) or your own StorageInterface.
8
- export { WebStorage, CapacitorPreferencesStorage } from './utils/storage';
8
+ export { WebStorage, CapacitorPreferencesStorage } from './utils/storage.js';
9
9
  // Error handling
10
- export { AuthError, isAuthError } from './utils/auth-error';
10
+ export { AuthError, isAuthError } from './utils/auth-error.js';
11
11
  // Logger — the shared default instance internals use, plus the class. Adjust verbosity with
12
12
  // `defaultLogger.setLevel('debug')` or build-time `VITE_LOG_LEVEL` / `LOG_LEVEL`.
13
- export { Logger, defaultLogger } from './utils/logger';
13
+ export { Logger, defaultLogger } from './utils/logger.js';
14
14
  // For backward compatibility with Capacitor plugin interface
15
- export { CapacitorAuthManager } from './capacitor-plugin';
15
+ export { CapacitorAuthManager } from './capacitor-plugin.js';
@@ -0,0 +1 @@
1
+ {"type":"module"}