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 +1 @@
1
- export { GoogleAuthProviderWeb } from './google-provider';
1
+ export { GoogleAuthProviderWeb } from './google-provider.js';
@@ -5,4 +5,4 @@
5
5
  // folder but are excluded from the published build until each is re-enabled and verified. Re-add a
6
6
  // provider's export below (and restore its registry loader + remove its tsconfig.build exclude) when
7
7
  // its turn comes.
8
- export { GoogleAuthProviderWeb } from './google-provider';
8
+ export { GoogleAuthProviderWeb } from './google-provider.js';
@@ -1,5 +1,5 @@
1
- import type { AuthUser } from '../definitions';
2
- import type { UseAuthReturn, UseAuthStateReturn, UseAuthProviderReturn } from './types';
1
+ import type { AuthUser } from '../definitions.js';
2
+ import type { UseAuthReturn, UseAuthStateReturn, UseAuthProviderReturn } from './types.js';
3
3
  /**
4
4
  * Hook for complete authentication functionality
5
5
  * @example
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useState, useCallback, useRef } from 'react';
2
- import { auth } from '../core/auth-manager';
2
+ import { auth } from '../core/auth-manager.js';
3
3
  /**
4
4
  * Hook for complete authentication functionality
5
5
  * @example
@@ -204,7 +204,7 @@ export function useAuthState() {
204
204
  */
205
205
  export function useAuthProvider(provider) {
206
206
  const [isSupported, setIsSupported] = useState(false);
207
- const [isConfigured, setIsConfigured] = useState(false);
207
+ const [isConfigured, setIsConfigured] = useState(() => auth.isProviderConfigured(provider));
208
208
  const [error, setError] = useState(null);
209
209
  const mountedRef = useRef(true);
210
210
  useEffect(() => {
@@ -1,3 +1,3 @@
1
- export * from './hooks';
2
- export * from './types';
3
- export { AuthProvider, AuthErrorCode } from '../definitions';
1
+ export * from './hooks.js';
2
+ export * from './types.js';
3
+ export { AuthProvider, AuthErrorCode } from '../definitions.js';
@@ -1,6 +1,6 @@
1
- export * from './hooks';
2
- export * from './types';
1
+ export * from './hooks.js';
2
+ export * from './types.js';
3
3
  // Re-export the AuthProvider enum (+ error codes) so consumers get `useAuth().signIn(AuthProvider.GOOGLE)`
4
4
  // with a single import. Using the enum is the recommended, typo-safe way to name a provider — plain
5
5
  // strings like 'google' still work.
6
- export { AuthProvider, AuthErrorCode } from '../definitions';
6
+ export { AuthProvider, AuthErrorCode } from '../definitions.js';
@@ -1,4 +1,4 @@
1
- import type { AuthUser, AuthResult, SignInOptions, SignOutOptions, LinkAccountOptions, UnlinkAccountOptions, GetIdTokenOptions, UpdateProfileOptions, DeleteAccountOptions } from '../definitions';
1
+ import type { AuthUser, AuthResult, SignInOptions, SignOutOptions, LinkAccountOptions, UnlinkAccountOptions, GetIdTokenOptions, UpdateProfileOptions, DeleteAccountOptions } from '../definitions.js';
2
2
  export interface UseAuthReturn {
3
3
  user: AuthUser | null;
4
4
  isLoading: boolean;
@@ -1,4 +1,4 @@
1
- import { AuthError as IAuthError, AuthProvider } from '../definitions';
1
+ import { AuthError as IAuthError, AuthProvider } from '../definitions.js';
2
2
  export declare class AuthError extends Error implements IAuthError {
3
3
  code: string;
4
4
  details?: Record<string, unknown>;
@@ -1,4 +1,4 @@
1
- import { AuthErrorCode, } from '../definitions';
1
+ import { AuthErrorCode, } from '../definitions.js';
2
2
  export class AuthError extends Error {
3
3
  constructor(code, message, provider, details) {
4
4
  super(message);
@@ -1,4 +1,4 @@
1
- import { Logger } from './logger';
1
+ import { Logger } from './logger.js';
2
2
  export type EventListener<T = unknown> = (data: T) => void;
3
3
  export type UnsubscribeFn = () => void;
4
4
  export declare class EventEmitter<T = unknown> {
@@ -1,4 +1,4 @@
1
- import { defaultLogger } from './logger';
1
+ import { defaultLogger } from './logger.js';
2
2
  export class EventEmitter {
3
3
  /**
4
4
  * @param logger Optional logger for listener errors. Defaults to the shared {@link defaultLogger}
@@ -1,4 +1,4 @@
1
- import { defaultLogger } from './logger';
1
+ import { defaultLogger } from './logger.js';
2
2
  export class PendingVerificationStore {
3
3
  /**
4
4
  * @param namespace Provider namespace (e.g. `'sms'`, `'email-code'`, `'magic-link'`). Keys are
@@ -1,5 +1,5 @@
1
- import { AuthPersistence } from '../definitions';
2
- import { Logger } from './logger';
1
+ import { AuthPersistence } from '../definitions.js';
2
+ import { Logger } from './logger.js';
3
3
  export interface StorageInterface {
4
4
  /**
5
5
  * Read and JSON-deserialize a value. Pass the expected shape as `T` at the call site to get a
@@ -1,5 +1,5 @@
1
- import { AuthPersistence } from '../definitions';
2
- import { defaultLogger } from './logger';
1
+ import { AuthPersistence } from '../definitions.js';
2
+ import { defaultLogger } from './logger.js';
3
3
  export class WebStorage {
4
4
  /**
5
5
  * @param persistence Where to persist values (local / session / in-memory).
@@ -12,17 +12,15 @@ export class WebStorage {
12
12
  this.logger = logger;
13
13
  switch (persistence) {
14
14
  case AuthPersistence.SESSION:
15
- this.storage = window.sessionStorage;
16
- break;
17
- case AuthPersistence.LOCAL:
18
- this.storage = window.localStorage;
15
+ this.storage = resolveBrowserStorage('sessionStorage');
19
16
  break;
20
17
  case AuthPersistence.NONE:
21
18
  // Use in-memory storage
22
19
  this.storage = new InMemoryStorage();
23
20
  break;
21
+ case AuthPersistence.LOCAL:
24
22
  default:
25
- this.storage = window.localStorage;
23
+ this.storage = resolveBrowserStorage('localStorage');
26
24
  }
27
25
  }
28
26
  async get(key) {
@@ -130,6 +128,32 @@ export class CapacitorPreferencesStorage {
130
128
  .map((k) => prefs.remove({ key: k })));
131
129
  }
132
130
  }
131
+ /**
132
+ * Returns the requested browser storage when it exists AND is usable, otherwise an in-memory
133
+ * fallback. Two environments make the fallback necessary:
134
+ * - Node / SSR / test runners: `window` is undefined, so the old unguarded `window.localStorage`
135
+ * read threw `ReferenceError: window is not defined` at import time (ISSUE-002).
136
+ * - Browsers that expose the API but refuse it (Safari private mode, cookies disabled, sandboxed
137
+ * iframes): `getItem`/`setItem` throw, so the probe below catches that and degrades gracefully.
138
+ */
139
+ function resolveBrowserStorage(kind) {
140
+ if (typeof window === 'undefined') {
141
+ return new InMemoryStorage();
142
+ }
143
+ try {
144
+ const candidate = window[kind];
145
+ if (!candidate) {
146
+ return new InMemoryStorage();
147
+ }
148
+ const probeKey = '__cap_auth_probe__';
149
+ candidate.setItem(probeKey, '1');
150
+ candidate.removeItem(probeKey);
151
+ return candidate;
152
+ }
153
+ catch (_a) {
154
+ return new InMemoryStorage();
155
+ }
156
+ }
133
157
  class InMemoryStorage {
134
158
  constructor() {
135
159
  this.data = new Map();
@@ -1,6 +1,6 @@
1
1
  import { Ref, ComputedRef } from 'vue';
2
- import type { AuthManagerConfig } from '../core/types';
3
- import type { AuthUser, AuthResult, SignInOptions, SignOutOptions, LinkAccountOptions, UnlinkAccountOptions, GetIdTokenOptions, UpdateProfileOptions, DeleteAccountOptions } from '../definitions';
2
+ import type { AuthManagerConfig } from '../core/types.js';
3
+ import type { AuthUser, AuthResult, SignInOptions, SignOutOptions, LinkAccountOptions, UnlinkAccountOptions, GetIdTokenOptions, UpdateProfileOptions, DeleteAccountOptions } from '../definitions.js';
4
4
  interface UseAuthReturn {
5
5
  user: Readonly<Ref<AuthUser | null>>;
6
6
  isLoading: Readonly<Ref<boolean>>;
@@ -1,5 +1,5 @@
1
1
  import { ref, computed, readonly, onUnmounted } from 'vue';
2
- import { auth } from '../core/auth-manager';
2
+ import { auth } from '../core/auth-manager.js';
3
3
  /**
4
4
  * Vue 3 composable for complete authentication functionality
5
5
  * @example
@@ -1,2 +1,2 @@
1
- export { useAuth, useAuthState, useUser, useAuthProvider, useAuthConfig, } from './composables';
2
- export { AuthProvider, AuthErrorCode } from '../definitions';
1
+ export { useAuth, useAuthState, useUser, useAuthProvider, useAuthConfig, } from './composables.js';
2
+ export { AuthProvider, AuthErrorCode } from '../definitions.js';
@@ -1,5 +1,5 @@
1
- export { useAuth, useAuthState, useUser, useAuthProvider, useAuthConfig, } from './composables';
1
+ export { useAuth, useAuthState, useUser, useAuthProvider, useAuthConfig, } from './composables.js';
2
2
  // Re-export the AuthProvider enum (+ error codes) so consumers get `useAuth().signIn(AuthProvider.GOOGLE)`
3
3
  // with a single import. Using the enum is the recommended, typo-safe way to name a provider — plain
4
4
  // strings like 'google' still work.
5
- export { AuthProvider, AuthErrorCode } from '../definitions';
5
+ export { AuthProvider, AuthErrorCode } from '../definitions.js';
package/dist/esm/web.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  import type { PluginListenerHandle } from '@capacitor/core';
3
- import type { CapacitorAuthManagerPlugin, AuthManagerInitOptions, SignInOptions, SignOutOptions, AuthResult, AuthUser, RefreshTokenOptions, AuthStateChangeCallback, IsSupportedOptions, IsSupportedResult, ConfigureOptions, LinkAccountOptions, UnlinkAccountOptions, PasswordResetOptions, EmailVerificationOptions, SendSmsCodeOptions, VerifySmsCodeOptions, SendEmailCodeOptions, VerifyEmailCodeOptions, UpdateProfileOptions, DeleteAccountOptions, GetIdTokenOptions, SetCustomParametersOptions, RevokeAccessOptions } from './definitions';
3
+ import type { CapacitorAuthManagerPlugin, AuthManagerInitOptions, SignInOptions, SignOutOptions, AuthResult, AuthUser, RefreshTokenOptions, AuthStateChangeCallback, IsSupportedOptions, IsSupportedResult, ConfigureOptions, LinkAccountOptions, UnlinkAccountOptions, PasswordResetOptions, EmailVerificationOptions, SendSmsCodeOptions, VerifySmsCodeOptions, SendEmailCodeOptions, VerifyEmailCodeOptions, UpdateProfileOptions, DeleteAccountOptions, GetIdTokenOptions, SetCustomParametersOptions, RevokeAccessOptions } from './definitions.js';
4
4
  export declare class CapacitorAuthManagerWeb extends WebPlugin implements CapacitorAuthManagerPlugin {
5
5
  private providers;
6
6
  private storage;
package/dist/esm/web.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
- import { AuthErrorCode, AuthPersistence, AuthProvider } from './definitions';
3
- import { AuthError } from './utils/auth-error';
4
- import { EventEmitter } from './utils/event-emitter';
5
- import { WebStorage } from './utils/storage';
6
- import { Logger } from './utils/logger';
7
- import { ProviderFactory } from './providers/provider-factory';
2
+ import { AuthErrorCode, AuthPersistence, AuthProvider } from './definitions.js';
3
+ import { AuthError } from './utils/auth-error.js';
4
+ import { EventEmitter } from './utils/event-emitter.js';
5
+ import { WebStorage } from './utils/storage.js';
6
+ import { Logger } from './utils/logger.js';
7
+ import { ProviderFactory } from './providers/provider-factory.js';
8
8
  export class CapacitorAuthManagerWeb extends WebPlugin {
9
9
  constructor() {
10
10
  super();