capacitor-auth-manager 1.0.0 → 2.1.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 (96) hide show
  1. package/Readme.md +395 -441
  2. package/dist/core.cjs.js +4952 -0
  3. package/dist/core.cjs.js.map +1 -0
  4. package/dist/esm/capacitor-plugin.d.ts +3 -0
  5. package/dist/esm/capacitor-plugin.js +7 -0
  6. package/dist/esm/capacitor-plugin.js.map +1 -0
  7. package/dist/esm/core/auth-manager.d.ts +33 -0
  8. package/dist/esm/core/auth-manager.js +296 -0
  9. package/dist/esm/core/auth-manager.js.map +1 -0
  10. package/dist/esm/core/index.d.ts +4 -0
  11. package/dist/esm/core/index.js +5 -0
  12. package/dist/esm/core/index.js.map +1 -0
  13. package/dist/esm/core/platform.d.ts +17 -0
  14. package/dist/esm/core/platform.js +80 -0
  15. package/dist/esm/core/platform.js.map +1 -0
  16. package/dist/esm/core/provider-registry.d.ts +21 -0
  17. package/dist/esm/core/provider-registry.js +605 -0
  18. package/dist/esm/core/provider-registry.js.map +1 -0
  19. package/dist/esm/core/types.d.ts +35 -0
  20. package/dist/esm/core/types.js +2 -0
  21. package/dist/esm/core/types.js.map +1 -0
  22. package/dist/esm/definitions.d.ts +45 -10
  23. package/dist/esm/definitions.js +14 -4
  24. package/dist/esm/definitions.js.map +1 -1
  25. package/dist/esm/index.d.ts +8 -4
  26. package/dist/esm/index.js +9 -6
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/providers/base-provider.d.ts +3 -1
  29. package/dist/esm/providers/base-provider.js +8 -5
  30. package/dist/esm/providers/base-provider.js.map +1 -1
  31. package/dist/esm/providers/oauth-provider.d.ts +38 -7
  32. package/dist/esm/providers/oauth-provider.js +35 -28
  33. package/dist/esm/providers/oauth-provider.js.map +1 -1
  34. package/dist/esm/providers/provider-factory.js +1 -1
  35. package/dist/esm/providers/provider-factory.js.map +1 -1
  36. package/dist/esm/providers/web/apple-provider.d.ts +32 -5
  37. package/dist/esm/providers/web/apple-provider.js +42 -35
  38. package/dist/esm/providers/web/apple-provider.js.map +1 -1
  39. package/dist/esm/providers/web/biometric-provider.d.ts +47 -0
  40. package/dist/esm/providers/web/biometric-provider.js +267 -0
  41. package/dist/esm/providers/web/biometric-provider.js.map +1 -0
  42. package/dist/esm/providers/web/email-password-provider.d.ts +55 -0
  43. package/dist/esm/providers/web/email-password-provider.js +429 -0
  44. package/dist/esm/providers/web/email-password-provider.js.map +1 -0
  45. package/dist/esm/providers/web/facebook-provider.d.ts +29 -0
  46. package/dist/esm/providers/web/facebook-provider.js +249 -0
  47. package/dist/esm/providers/web/facebook-provider.js.map +1 -0
  48. package/dist/esm/providers/web/firebase-provider.d.ts +20 -0
  49. package/dist/esm/providers/web/firebase-provider.js +306 -0
  50. package/dist/esm/providers/web/firebase-provider.js.map +1 -0
  51. package/dist/esm/providers/web/github-provider.d.ts +25 -0
  52. package/dist/esm/providers/web/github-provider.js +248 -0
  53. package/dist/esm/providers/web/github-provider.js.map +1 -0
  54. package/dist/esm/providers/web/google-provider.d.ts +98 -7
  55. package/dist/esm/providers/web/google-provider.js +37 -23
  56. package/dist/esm/providers/web/google-provider.js.map +1 -1
  57. package/dist/esm/providers/web/index.d.ts +13 -0
  58. package/dist/esm/providers/web/index.js +15 -0
  59. package/dist/esm/providers/web/index.js.map +1 -0
  60. package/dist/esm/providers/web/linkedin-provider.d.ts +38 -0
  61. package/dist/esm/providers/web/linkedin-provider.js +152 -0
  62. package/dist/esm/providers/web/linkedin-provider.js.map +1 -0
  63. package/dist/esm/providers/web/magic-link-provider.d.ts +46 -0
  64. package/dist/esm/providers/web/magic-link-provider.js +298 -0
  65. package/dist/esm/providers/web/magic-link-provider.js.map +1 -0
  66. package/dist/esm/providers/web/microsoft-provider.d.ts +21 -0
  67. package/dist/esm/providers/web/microsoft-provider.js +211 -0
  68. package/dist/esm/providers/web/microsoft-provider.js.map +1 -0
  69. package/dist/esm/providers/web/slack-provider.d.ts +40 -0
  70. package/dist/esm/providers/web/slack-provider.js +151 -0
  71. package/dist/esm/providers/web/slack-provider.js.map +1 -0
  72. package/dist/esm/providers/web/sms-provider.d.ts +48 -0
  73. package/dist/esm/providers/web/sms-provider.js +301 -0
  74. package/dist/esm/providers/web/sms-provider.js.map +1 -0
  75. package/dist/esm/providers/web/username-password-provider.d.ts +62 -0
  76. package/dist/esm/providers/web/username-password-provider.js +432 -0
  77. package/dist/esm/providers/web/username-password-provider.js.map +1 -0
  78. package/dist/esm/utils/auth-error.d.ts +5 -5
  79. package/dist/esm/utils/auth-error.js +14 -5
  80. package/dist/esm/utils/auth-error.js.map +1 -1
  81. package/dist/esm/utils/event-emitter.d.ts +2 -2
  82. package/dist/esm/utils/event-emitter.js +1 -1
  83. package/dist/esm/utils/event-emitter.js.map +1 -1
  84. package/dist/esm/utils/logger.d.ts +4 -4
  85. package/dist/esm/utils/logger.js.map +1 -1
  86. package/dist/esm/utils/storage.d.ts +4 -4
  87. package/dist/esm/utils/storage.js +13 -3
  88. package/dist/esm/utils/storage.js.map +1 -1
  89. package/dist/esm/web.js +7 -3
  90. package/dist/esm/web.js.map +1 -1
  91. package/dist/plugin.cjs.js +4172 -407
  92. package/dist/plugin.cjs.js.map +1 -1
  93. package/dist/plugin.js +4172 -407
  94. package/dist/plugin.js.map +1 -1
  95. package/package.json +79 -18
  96. package/scripts/configure.js +105 -61
package/Readme.md CHANGED
@@ -1,588 +1,542 @@
1
1
  # Capacitor Auth Manager
2
2
 
3
- A comprehensive authentication plugin for Capacitor that provides secure, type-safe, and framework-independent authentication implementations across Android, iOS, and Web platforms.
3
+ Universal authentication manager with 13+ providers. Framework-agnostic, works with React, Vue, Angular, and vanilla JS. Optional Capacitor support for mobile apps.
4
+
5
+ ## 🚀 v2.0 - Complete Rewrite!
6
+
7
+ Version 2.0 is a complete rewrite focusing on developer experience, smaller bundle sizes, and flexibility:
8
+
9
+ - **No Provider Wrappers** - Works like Zustand, no context providers needed
10
+ - **Framework Agnostic** - One package for React, Vue, Angular, and vanilla JS
11
+ - **Optional Capacitor** - Use in regular web apps without Capacitor
12
+ - **Dynamic Loading** - Providers load only when used (better tree-shaking)
13
+ - **All 13 Providers Implemented** - Every promised provider is now available
4
14
 
5
15
  ## Features
6
16
 
7
- - 🔐 **13+ Authentication Providers**: Google, Apple, Microsoft, Facebook, GitHub, Slack, LinkedIn, Firebase, Email Magic Link, SMS, Email/Phone/Username + Password, Email Code, and Biometric Auth
8
- - 📱 **Cross-Platform**: Works seamlessly on iOS, Android, and Web
9
- - 🔄 **Subscribable Auth State**: Real-time authentication state updates
10
- - 🎯 **Type-Safe**: Full TypeScript support with comprehensive type definitions
11
- - 🏗️ **Framework Independent**: Works with any JavaScript framework
12
- - 🔒 **Secure**: Uses only official SDKs and follows security best practices
13
- - ⚡ **Performant**: Optimized for minimal overhead and fast authentication flows
14
- - 🔧 **Highly Configurable**: Each provider can be configured with all available options
17
+ - 🚀 **Zero Configuration** - Works out of the box with sensible defaults
18
+ - 🎯 **Framework Agnostic** - Use with React, Vue, Angular, or vanilla JavaScript
19
+ - 📦 **Tiny Bundle Size** - Only includes what you use with tree-shaking
20
+ - 🔌 **13+ Auth Providers** - Google, Apple, Microsoft, Facebook, GitHub, and more
21
+ - 🔄 **Provider-less Design** - No context providers required (like Zustand)
22
+ - 📱 **Optional Capacitor** - Works in web apps without Capacitor
23
+ - 🎨 **TypeScript First** - Full type safety and IntelliSense
24
+ - 🔐 **Secure by Default** - Follows security best practices
25
+ - ⚡ **Dynamic Loading** - Providers load only when used
26
+
27
+ ## Quick Start
15
28
 
16
- ## Installation
29
+ ### Installation
17
30
 
18
31
  ```bash
19
32
  npm install capacitor-auth-manager
20
- npx cap sync
33
+ # or
34
+ yarn add capacitor-auth-manager
21
35
  ```
22
36
 
23
- ## Quick Start
37
+ ### Basic Usage (Vanilla JavaScript)
24
38
 
25
- ```typescript
26
- import { CapacitorAuthManager, AuthProvider } from 'capacitor-auth-manager';
39
+ ```javascript
40
+ import { auth } from 'capacitor-auth-manager';
27
41
 
28
- // Initialize the auth manager
29
- await CapacitorAuthManager.initialize({
30
- providers: [
31
- {
32
- provider: AuthProvider.GOOGLE,
33
- options: {
34
- clientId: 'YOUR_GOOGLE_CLIENT_ID',
35
- scopes: ['email', 'profile']
36
- }
42
+ // Configure providers
43
+ auth.configure({
44
+ providers: {
45
+ google: {
46
+ clientId: 'YOUR_GOOGLE_CLIENT_ID',
37
47
  },
38
- {
39
- provider: AuthProvider.APPLE,
40
- options: {
41
- clientId: 'YOUR_APPLE_CLIENT_ID',
42
- redirectUri: 'YOUR_REDIRECT_URI'
43
- }
44
- }
45
- ],
46
- persistence: 'local', // 'local' | 'session' | 'none'
47
- autoRefreshToken: true,
48
- enableLogging: true
49
- });
50
-
51
- // Sign in with Google
52
- const result = await CapacitorAuthManager.signIn({
53
- provider: AuthProvider.GOOGLE
48
+ apple: {
49
+ clientId: 'YOUR_APPLE_CLIENT_ID',
50
+ redirectUri: 'YOUR_REDIRECT_URI',
51
+ },
52
+ },
54
53
  });
55
54
 
56
- console.log('Signed in user:', result.user);
55
+ // Sign in
56
+ const result = await auth.signIn('google');
57
+ console.log('Welcome', result.user.displayName);
57
58
 
58
59
  // Listen to auth state changes
59
- const listener = await CapacitorAuthManager.addAuthStateListener((user) => {
60
- console.log('Auth state changed:', user);
60
+ auth.onAuthStateChange((state) => {
61
+ console.log('User:', state.user);
62
+ console.log('Authenticated:', state.isAuthenticated);
61
63
  });
62
64
 
63
65
  // Sign out
64
- await CapacitorAuthManager.signOut();
66
+ await auth.signOut();
65
67
  ```
66
68
 
67
- ## Configuration
69
+ ### React Usage
68
70
 
69
- ### Platform-Specific Setup
70
-
71
- #### iOS Setup
72
-
73
- 1. Add required capabilities in Xcode:
74
- - Sign in with Apple (if using Apple Auth)
75
- - Keychain Sharing (for secure credential storage)
76
-
77
- 2. Update your `Info.plist`:
78
- ```xml
79
- <!-- For Google Sign-In -->
80
- <key>CFBundleURLTypes</key>
81
- <array>
82
- <dict>
83
- <key>CFBundleURLSchemes</key>
84
- <array>
85
- <string>YOUR_REVERSED_CLIENT_ID</string>
86
- </array>
87
- </dict>
88
- </array>
89
-
90
- <!-- For Facebook Login -->
91
- <key>FacebookAppID</key>
92
- <string>YOUR_FACEBOOK_APP_ID</string>
93
- <key>FacebookClientToken</key>
94
- <string>YOUR_FACEBOOK_CLIENT_TOKEN</string>
95
- <key>FacebookDisplayName</key>
96
- <string>YOUR_APP_NAME</string>
97
-
98
- <!-- For OAuth redirects -->
99
- <key>LSApplicationQueriesSchemes</key>
100
- <array>
101
- <string>fbapi</string>
102
- <string>fb-messenger-share-api</string>
103
- <string>fbauth2</string>
104
- <string>fbshareextension</string>
105
- </array>
106
- ```
71
+ ```tsx
72
+ import { useAuth } from 'capacitor-auth-manager/react';
107
73
 
108
- #### Android Setup
74
+ function LoginButton() {
75
+ const { user, signIn, signOut, isLoading } = useAuth();
109
76
 
110
- 1. Add to your `android/app/build.gradle`:
111
- ```gradle
112
- android {
113
- defaultConfig {
114
- manifestPlaceholders = [
115
- appAuthRedirectScheme: 'com.yourcompany.yourapp'
116
- ]
77
+ if (isLoading) return <div>Loading...</div>;
78
+
79
+ if (user) {
80
+ return (
81
+ <div>
82
+ <p>Welcome, {user.displayName}!</p>
83
+ <button onClick={() => signOut()}>Sign Out</button>
84
+ </div>
85
+ );
117
86
  }
87
+
88
+ return <button onClick={() => signIn('google')}>Sign In with Google</button>;
118
89
  }
119
90
  ```
120
91
 
121
- 2. Update your `AndroidManifest.xml`:
122
- ```xml
123
- <!-- For Google Sign-In -->
124
- <meta-data
125
- android:name="com.google.android.gms.auth.api.signin.GoogleSignInOptions"
126
- android:value="@string/default_web_client_id" />
127
-
128
- <!-- For Facebook Login -->
129
- <meta-data
130
- android:name="com.facebook.sdk.ApplicationId"
131
- android:value="@string/facebook_app_id"/>
132
- <meta-data
133
- android:name="com.facebook.sdk.ClientToken"
134
- android:value="@string/facebook_client_token"/>
92
+ No providers or context wrappers needed! Just import and use.
93
+
94
+ ### Vue 3 Usage
95
+
96
+ ```vue
97
+ <script setup>
98
+ import { useAuth } from 'capacitor-auth-manager/vue';
99
+
100
+ const { user, signIn, signOut, isLoading } = useAuth();
101
+ </script>
102
+
103
+ <template>
104
+ <div v-if="isLoading">Loading...</div>
105
+ <div v-else-if="user">
106
+ <p>Welcome, {{ user.displayName }}!</p>
107
+ <button @click="signOut">Sign Out</button>
108
+ </div>
109
+ <button
110
+ v-else
111
+ @click="signIn('google')"
112
+ >
113
+ Sign In with Google
114
+ </button>
115
+ </template>
135
116
  ```
136
117
 
137
- #### Web Setup
118
+ ### Angular Usage
138
119
 
139
- For web platform, make sure your redirect URIs are properly configured in each provider's console:
120
+ ```typescript
121
+ import { Component } from '@angular/core';
122
+ import { AuthService } from 'capacitor-auth-manager/angular';
123
+
124
+ @Component({
125
+ selector: 'app-login',
126
+ template: `
127
+ <div *ngIf="authService.isLoading$ | async">Loading...</div>
128
+ <div *ngIf="authService.user$ | async as user">
129
+ <p>Welcome, {{ user.displayName }}!</p>
130
+ <button (click)="signOut()">Sign Out</button>
131
+ </div>
132
+ <button
133
+ *ngIf="!(authService.user$ | async)"
134
+ (click)="signIn('google')"
135
+ >
136
+ Sign In with Google
137
+ </button>
138
+ `,
139
+ })
140
+ export class LoginComponent {
141
+ constructor(public authService: AuthService) {}
142
+
143
+ signIn(provider: string) {
144
+ this.authService.signIn(provider).subscribe();
145
+ }
140
146
 
141
- - **Google**: Add your domain to authorized JavaScript origins
142
- - **Apple**: Configure your Service ID with proper domains and redirect URLs
143
- - **Facebook**: Add your domain to valid OAuth redirect URIs
144
- - **Microsoft**: Configure redirect URIs in Azure AD
147
+ signOut() {
148
+ this.authService.signOut().subscribe();
149
+ }
150
+ }
151
+ ```
152
+
153
+ ## Supported Providers
154
+
155
+ | Provider | Web | iOS | Android | Status |
156
+ | ----------------- | --- | --- | ------- | -------------- |
157
+ | Google | ✅ | ✅ | ✅ | ✅ Implemented |
158
+ | Apple | ✅ | ✅ | ❌ | ✅ Implemented |
159
+ | Microsoft | ✅ | ✅ | ✅ | ✅ Implemented |
160
+ | Facebook | ✅ | ✅ | ✅ | ✅ Implemented |
161
+ | GitHub | ✅ | ❌ | ❌ | ✅ Implemented |
162
+ | Firebase | ✅ | ✅ | ✅ | ✅ Implemented |
163
+ | Email Magic Link | ✅ | ✅ | ✅ | ✅ Implemented |
164
+ | SMS | ✅ | ✅ | ✅ | ✅ Implemented |
165
+ | Email/Password | ✅ | ✅ | ✅ | ✅ Implemented |
166
+ | Biometric | ❌ | ✅ | ✅ | ✅ Implemented |
167
+ | Slack | ✅ | ❌ | ❌ | ✅ Implemented |
168
+ | LinkedIn | ✅ | ❌ | ❌ | ✅ Implemented |
169
+ | Username/Password | ✅ | ✅ | ✅ | ✅ Implemented |
145
170
 
146
- ## Authentication Providers
171
+ ## Configuration
147
172
 
148
- ### Google Authentication
173
+ ### Complete Configuration Example
149
174
 
150
175
  ```typescript
151
- await CapacitorAuthManager.initialize({
152
- providers: [{
153
- provider: AuthProvider.GOOGLE,
154
- options: {
155
- clientId: 'YOUR_GOOGLE_CLIENT_ID',
176
+ import { auth } from 'capacitor-auth-manager';
177
+
178
+ auth.configure({
179
+ // Provider configurations
180
+ providers: {
181
+ google: {
182
+ clientId: 'YOUR_CLIENT_ID',
156
183
  scopes: ['email', 'profile'],
157
- serverClientId: 'YOUR_SERVER_CLIENT_ID', // For Android
158
- offlineAccess: true, // To get refresh token
159
- hostedDomain: 'yourdomain.com', // Restrict to domain
160
- forceCodeForRefreshToken: true
161
- }
162
- }]
163
- });
184
+ },
185
+ apple: {
186
+ clientId: 'YOUR_SERVICE_ID',
187
+ redirectUri: 'https://your-app.com/auth/callback',
188
+ },
189
+ microsoft: {
190
+ clientId: 'YOUR_CLIENT_ID',
191
+ authority: 'https://login.microsoftonline.com/common',
192
+ },
193
+ facebook: {
194
+ appId: 'YOUR_APP_ID',
195
+ version: 'v18.0',
196
+ },
197
+ github: {
198
+ clientId: 'YOUR_CLIENT_ID',
199
+ redirectUri: 'YOUR_REDIRECT_URI',
200
+ },
201
+ firebase: {
202
+ apiKey: 'YOUR_API_KEY',
203
+ authDomain: 'YOUR_AUTH_DOMAIN',
204
+ projectId: 'YOUR_PROJECT_ID',
205
+ },
206
+ 'magic-link': {
207
+ sendLinkUrl: 'https://your-api.com/send-magic-link',
208
+ verifyUrl: 'https://your-api.com/verify-magic-link',
209
+ },
210
+ sms: {
211
+ sendCodeUrl: 'https://your-api.com/sms/send',
212
+ verifyCodeUrl: 'https://your-api.com/sms/verify',
213
+ },
214
+ 'email-password': {
215
+ apiUrl: 'https://your-api.com',
216
+ passwordRequirements: {
217
+ minLength: 8,
218
+ requireUppercase: true,
219
+ requireNumbers: true,
220
+ },
221
+ },
222
+ biometric: {
223
+ reason: 'Authenticate to access your account',
224
+ title: 'Authentication Required',
225
+ },
226
+ slack: {
227
+ clientId: 'YOUR_CLIENT_ID',
228
+ redirectUri: 'https://your-app.com/auth/slack/callback',
229
+ teamId: 'OPTIONAL_TEAM_ID', // Restrict to specific workspace
230
+ },
231
+ linkedin: {
232
+ clientId: 'YOUR_CLIENT_ID',
233
+ redirectUri: 'https://your-app.com/auth/linkedin/callback',
234
+ },
235
+ 'username-password': {
236
+ apiUrl: 'https://your-api.com',
237
+ usernameRequirements: {
238
+ minLength: 3,
239
+ maxLength: 20,
240
+ },
241
+ allowSignUp: true,
242
+ },
243
+ },
164
244
 
165
- const result = await CapacitorAuthManager.signIn({
166
- provider: AuthProvider.GOOGLE,
167
- options: {
168
- loginHint: 'user@example.com', // Pre-fill email
169
- prompt: 'select_account' // Force account selection
170
- }
245
+ // Global options
246
+ persistence: 'local', // 'local' | 'session' | 'memory'
247
+ autoRefreshToken: true,
248
+ tokenRefreshBuffer: 300000, // 5 minutes before expiry
249
+ enableLogging: true,
250
+ logLevel: 'debug', // 'debug' | 'info' | 'warn' | 'error'
171
251
  });
172
252
  ```
173
253
 
174
- ### Apple Authentication
254
+ ### Provider-Specific Setup
175
255
 
176
- ```typescript
177
- await CapacitorAuthManager.initialize({
178
- providers: [{
179
- provider: AuthProvider.APPLE,
180
- options: {
181
- clientId: 'YOUR_SERVICE_ID',
182
- redirectUri: 'https://yourapp.com/auth/callback',
183
- scopes: [AppleAuthScope.EMAIL, AppleAuthScope.NAME],
184
- usePopup: true,
185
- state: 'YOUR_STATE', // Optional state parameter
186
- nonce: 'YOUR_NONCE' // Optional nonce for security
187
- }
188
- }]
189
- });
256
+ Each provider may require additional setup. The package provides helpful error messages when dependencies are missing.
190
257
 
191
- const result = await CapacitorAuthManager.signIn({
192
- provider: AuthProvider.APPLE
193
- });
194
- ```
258
+ ## Framework-Specific APIs
195
259
 
196
- ### Microsoft Authentication
260
+ ### React Hooks
197
261
 
198
- ```typescript
199
- await CapacitorAuthManager.initialize({
200
- providers: [{
201
- provider: AuthProvider.MICROSOFT,
202
- options: {
203
- clientId: 'YOUR_AZURE_CLIENT_ID',
204
- tenantId: 'YOUR_TENANT_ID', // or 'common' for multi-tenant
205
- redirectUri: 'https://yourapp.com/auth/callback',
206
- scopes: ['openid', 'profile', 'email'],
207
- authority: 'https://login.microsoftonline.com/YOUR_TENANT_ID'
208
- }
209
- }]
210
- });
211
- ```
262
+ - `useAuth()` - Complete authentication functionality
263
+ - `useAuthState()` - Read-only authentication state
264
+ - `useUser()` - Just the current user
265
+ - `useToken()` - Access token management
266
+ - `useIsAuthenticated()` - Boolean authentication status
267
+
268
+ ### Vue 3 Composables
212
269
 
213
- ### Firebase Authentication
270
+ - `useAuth()` - Complete authentication functionality with reactive refs
271
+ - `useAuthState()` - Reactive auth state
272
+ - `useUser()` - Reactive user ref
273
+ - `useToken()` - Reactive token management
274
+
275
+ ### Angular Service
214
276
 
215
277
  ```typescript
216
- await CapacitorAuthManager.initialize({
217
- providers: [{
218
- provider: AuthProvider.FIREBASE,
219
- options: {
220
- apiKey: 'YOUR_FIREBASE_API_KEY',
221
- authDomain: 'your-app.firebaseapp.com',
222
- projectId: 'your-project-id',
223
- storageBucket: 'your-app.appspot.com',
224
- messagingSenderId: 'YOUR_SENDER_ID',
225
- appId: 'YOUR_APP_ID'
226
- }
227
- }]
228
- });
278
+ import { AuthModule } from 'capacitor-auth-manager/angular';
279
+
280
+ // In your app module
281
+ imports: [
282
+ AuthModule.forRoot({
283
+ providers: {
284
+ /* ... */
285
+ },
286
+ }),
287
+ ];
229
288
  ```
230
289
 
231
- ### Email/Password Authentication
290
+ ## Advanced Usage
232
291
 
233
- ```typescript
234
- await CapacitorAuthManager.initialize({
235
- providers: [{
236
- provider: AuthProvider.EMAIL_PASSWORD,
237
- options: {
238
- strengthRequirements: {
239
- minLength: 8,
240
- requireUppercase: true,
241
- requireNumbers: true,
242
- requireSpecialCharacters: true
243
- },
244
- allowPasswordReset: true,
245
- requireEmailVerification: true
246
- }
247
- }]
248
- });
292
+ ### Email Magic Link
249
293
 
250
- // Sign up
251
- const result = await CapacitorAuthManager.signIn({
252
- provider: AuthProvider.EMAIL_PASSWORD,
253
- credentials: {
254
- email: 'user@example.com',
255
- password: 'SecurePassword123!'
256
- }
257
- });
294
+ ```typescript
295
+ // Send magic link
296
+ await auth.signIn('magic-link', { email: 'user@example.com' });
258
297
 
259
- // Password reset
260
- await CapacitorAuthManager.sendPasswordResetEmail({
261
- email: 'user@example.com'
262
- });
298
+ // The user will receive an email with a link
299
+ // When they click it, your app handles the callback
263
300
  ```
264
301
 
265
302
  ### SMS Authentication
266
303
 
267
304
  ```typescript
268
- await CapacitorAuthManager.initialize({
269
- providers: [{
270
- provider: AuthProvider.SMS,
271
- options: {
272
- provider: 'twilio', // or 'firebase', 'custom'
273
- twilioConfig: {
274
- accountSid: 'YOUR_ACCOUNT_SID',
275
- authToken: 'YOUR_AUTH_TOKEN',
276
- fromNumber: '+1234567890'
277
- },
278
- codeLength: 6,
279
- codeExpiration: 300000, // 5 minutes
280
- maxAttempts: 3
281
- }
282
- }]
283
- });
284
-
285
305
  // Send SMS code
286
- await CapacitorAuthManager.sendSmsCode({
287
- phoneNumber: '+1234567890'
288
- });
306
+ const result = await auth.signIn('sms', { phoneNumber: '+1234567890' });
289
307
 
290
308
  // Verify SMS code
291
- const result = await CapacitorAuthManager.verifySmsCode({
309
+ await auth.signIn('sms', {
292
310
  phoneNumber: '+1234567890',
293
- code: '123456'
311
+ code: '123456',
294
312
  });
295
313
  ```
296
314
 
297
- ### Biometric Authentication
298
-
299
- Note: For biometric authentication, this plugin integrates with [capacitor-biometric-authentication](https://www.npmjs.com/package/capacitor-biometric-authentication).
315
+ ### Email/Password
300
316
 
301
317
  ```typescript
302
- await CapacitorAuthManager.initialize({
303
- providers: [{
304
- provider: AuthProvider.BIOMETRIC,
305
- options: {
306
- fallbackToPasscode: true,
307
- title: 'Authenticate',
308
- subtitle: 'Use your biometric to sign in',
309
- description: 'Place your finger on the sensor',
310
- negativeButtonText: 'Cancel',
311
- maxAttempts: 3
312
- }
313
- }]
318
+ // Sign up
319
+ await auth.signUp({
320
+ email: 'user@example.com',
321
+ password: 'secure-password',
322
+ displayName: 'John Doe',
314
323
  });
315
324
 
316
- const result = await CapacitorAuthManager.signIn({
317
- provider: AuthProvider.BIOMETRIC
325
+ // Sign in
326
+ await auth.signIn('email-password', {
327
+ email: 'user@example.com',
328
+ password: 'secure-password',
318
329
  });
319
- ```
320
-
321
- ## API Reference
322
-
323
- ### Core Methods
324
330
 
325
- #### initialize(options)
326
- Initializes the auth manager with provider configurations.
331
+ // Update password
332
+ const provider = await auth.getProvider('email-password');
333
+ await provider.updatePassword('oldPassword', 'newPassword');
327
334
 
328
- ```typescript
329
- interface AuthManagerInitOptions {
330
- providers: AuthProviderConfig[];
331
- persistence?: 'local' | 'session' | 'none';
332
- autoRefreshToken?: boolean;
333
- tokenRefreshBuffer?: number; // ms before token expiry
334
- enableLogging?: boolean;
335
- logLevel?: 'debug' | 'info' | 'warn' | 'error';
336
- }
335
+ // Send password reset
336
+ await provider.sendPasswordResetEmail('user@example.com');
337
337
  ```
338
338
 
339
- #### signIn(options)
340
- Signs in a user with the specified provider.
339
+ ### Biometric Authentication
341
340
 
342
341
  ```typescript
343
- interface SignInOptions {
344
- provider: AuthProvider;
345
- credentials?: AuthCredentials;
346
- options?: SignInProviderOptions;
347
- }
348
- ```
342
+ // Check availability
343
+ const biometric = await auth.getProvider('biometric');
344
+ const { available, biometryType } = await biometric.isAvailable();
349
345
 
350
- #### signOut(options?)
351
- Signs out the current user or a specific provider.
346
+ if (available) {
347
+ // Store credentials after initial sign in
348
+ const result = await auth.signIn('google');
349
+ await biometric.storeUserCredentials(result.user, result.credential);
352
350
 
353
- ```typescript
354
- interface SignOutOptions {
355
- provider?: AuthProvider;
356
- revokeToken?: boolean;
357
- clearCache?: boolean;
358
- redirectUrl?: string;
351
+ // Later: authenticate with biometrics
352
+ await auth.signIn('biometric');
359
353
  }
360
354
  ```
361
355
 
362
- #### getCurrentUser()
363
- Returns the currently authenticated user.
356
+ ### Username/Password Authentication
364
357
 
365
358
  ```typescript
366
- const user = await CapacitorAuthManager.getCurrentUser();
367
- ```
368
-
369
- #### addAuthStateListener(callback)
370
- Subscribes to authentication state changes.
359
+ // Sign up with username
360
+ await auth.signUp({
361
+ username: 'johndoe',
362
+ password: 'secure-password',
363
+ email: 'john@example.com', // optional
364
+ displayName: 'John Doe', // optional
365
+ });
371
366
 
372
- ```typescript
373
- const listener = await CapacitorAuthManager.addAuthStateListener((user) => {
374
- if (user) {
375
- console.log('User signed in:', user);
376
- } else {
377
- console.log('User signed out');
378
- }
367
+ // Sign in
368
+ await auth.signIn('username-password', {
369
+ username: 'johndoe',
370
+ password: 'secure-password',
379
371
  });
380
372
 
381
- // Remove listener
382
- await listener.remove();
373
+ // Check username availability
374
+ const provider = await auth.getProvider('username-password');
375
+ const isAvailable = await provider.checkUsernameAvailability('johndoe');
383
376
  ```
384
377
 
385
- #### refreshToken(options?)
386
- Manually refreshes the authentication token.
378
+ ### Slack Authentication
387
379
 
388
380
  ```typescript
389
- const result = await CapacitorAuthManager.refreshToken({
390
- provider: AuthProvider.GOOGLE,
391
- forceRefresh: true
381
+ // Sign in with Slack
382
+ await auth.signIn('slack');
383
+
384
+ // Restrict to specific workspace
385
+ auth.configure({
386
+ providers: {
387
+ slack: {
388
+ clientId: 'YOUR_CLIENT_ID',
389
+ redirectUri: 'YOUR_REDIRECT_URI',
390
+ teamId: 'SPECIFIC_TEAM_ID', // Optional
391
+ },
392
+ },
392
393
  });
393
394
  ```
394
395
 
395
- ### Account Management
396
-
397
- #### linkAccount(options)
398
- Links an additional authentication provider to the current user.
396
+ ### LinkedIn Authentication
399
397
 
400
398
  ```typescript
401
- await CapacitorAuthManager.linkAccount({
402
- provider: AuthProvider.GOOGLE
399
+ // Sign in with LinkedIn
400
+ await auth.signIn('linkedin');
401
+
402
+ // Configure with scopes
403
+ auth.configure({
404
+ providers: {
405
+ linkedin: {
406
+ clientId: 'YOUR_CLIENT_ID',
407
+ redirectUri: 'YOUR_REDIRECT_URI',
408
+ scopes: ['openid', 'profile', 'email'],
409
+ },
410
+ },
403
411
  });
404
412
  ```
405
413
 
406
- #### unlinkAccount(options)
407
- Unlinks an authentication provider from the current user.
414
+ ### Multiple Sign-In Options
408
415
 
409
416
  ```typescript
410
- await CapacitorAuthManager.unlinkAccount({
411
- provider: AuthProvider.GOOGLE
412
- });
413
- ```
417
+ // Simple provider name
418
+ await auth.signIn('google');
414
419
 
415
- #### updateProfile(options)
416
- Updates the user's profile information.
420
+ // With scopes
421
+ await auth.signIn('google', {
422
+ scopes: ['https://www.googleapis.com/auth/calendar'],
423
+ });
417
424
 
418
- ```typescript
419
- await CapacitorAuthManager.updateProfile({
420
- displayName: 'John Doe',
421
- photoURL: 'https://example.com/photo.jpg'
425
+ // With login hint
426
+ await auth.signIn('google', {
427
+ loginHint: 'user@example.com',
422
428
  });
423
429
  ```
424
430
 
425
- #### deleteAccount(options?)
426
- Deletes the current user's account.
431
+ ### Token Management
427
432
 
428
433
  ```typescript
429
- await CapacitorAuthManager.deleteAccount({
430
- requireReauthentication: true
434
+ // Listen to token state
435
+ auth.onAuthStateChange((state) => {
436
+ if (state.credential?.expiresAt) {
437
+ console.log('Token expires at:', new Date(state.credential.expiresAt));
438
+ }
431
439
  });
440
+
441
+ // Manual token refresh
442
+ await auth.refreshToken();
443
+
444
+ // Get current token
445
+ const state = auth.getAuthState();
446
+ const token = state.credential?.accessToken;
432
447
  ```
433
448
 
434
- ### Utility Methods
449
+ ## Examples
435
450
 
436
- #### isSupported(options)
437
- Checks if a provider is supported on the current platform.
451
+ Check out the [examples](./examples) directory for complete applications:
438
452
 
439
- ```typescript
440
- const result = await CapacitorAuthManager.isSupported({
441
- provider: AuthProvider.APPLE
442
- });
453
+ - [Vanilla JavaScript](./examples/vanilla-js) - Pure JS implementation
454
+ - [React Example](./examples/react) - React 18+ with TypeScript
455
+ - [Vue 3 Example](./examples/vue) - Vue 3 Composition API
456
+ - [Angular Example](./examples/angular) - Angular 16+ with standalone components
443
457
 
444
- if (result.isSupported) {
445
- // Provider is available
446
- }
447
- ```
458
+ ## Migration from v1.x
448
459
 
449
- #### getIdToken(options?)
450
- Gets the current ID token for the authenticated user.
460
+ ### Before (v1.x)
451
461
 
452
462
  ```typescript
453
- const token = await CapacitorAuthManager.getIdToken({
454
- forceRefresh: true
463
+ // Required Capacitor
464
+ import { CapacitorAuthManager } from 'capacitor-auth-manager';
465
+
466
+ await CapacitorAuthManager.initialize({
467
+ providers: [
468
+ /* ... */
469
+ ],
455
470
  });
456
- ```
457
471
 
458
- ## Error Handling
472
+ await CapacitorAuthManager.signIn({ provider: AuthProvider.GOOGLE });
473
+ ```
459
474
 
460
- The plugin provides detailed error codes for different scenarios:
475
+ ### After (v2.0)
461
476
 
462
477
  ```typescript
463
- try {
464
- await CapacitorAuthManager.signIn({
465
- provider: AuthProvider.GOOGLE
466
- });
467
- } catch (error) {
468
- switch (error.code) {
469
- case 'auth/user-cancelled':
470
- // User cancelled the sign-in flow
471
- break;
472
- case 'auth/network-error':
473
- // Network error occurred
474
- break;
475
- case 'auth/invalid-credentials':
476
- // Invalid credentials provided
477
- break;
478
- case 'auth/popup-blocked':
479
- // Popup was blocked by browser
480
- break;
481
- default:
482
- // Other error
483
- console.error('Auth error:', error);
484
- }
485
- }
486
- ```
478
+ // Works without Capacitor
479
+ import { auth } from 'capacitor-auth-manager';
487
480
 
488
- ## Security Considerations
481
+ auth.configure({
482
+ providers: { google: { clientId: '...' } },
483
+ });
489
484
 
490
- 1. **Client IDs and Secrets**: Never expose client secrets in your client-side code
491
- 2. **Token Storage**: Tokens are securely stored using platform-specific secure storage
492
- 3. **HTTPS Required**: Always use HTTPS in production for web implementations
493
- 4. **Validate Tokens**: Always validate tokens on your backend before trusting them
494
- 5. **Biometric Security**: Biometric data never leaves the device
485
+ await auth.signIn('google');
486
+ ```
487
+
488
+ ## Why v2.0?
495
489
 
496
- ## Migration Guide
490
+ 1. **No Context Providers** - Works like Zustand, cleaner component trees
491
+ 2. **Framework Agnostic** - One package, multiple frameworks
492
+ 3. **Better Tree-shaking** - Only pay for what you use
493
+ 4. **Optional Capacitor** - Use in any web app
494
+ 5. **All Providers Ready** - No more "coming soon"
497
495
 
498
- If you're migrating from other authentication solutions:
496
+ ## TypeScript Support
499
497
 
500
- ### From Firebase Auth
498
+ Full TypeScript support with detailed types:
501
499
 
502
500
  ```typescript
503
- // Before (Firebase Auth)
504
- import { getAuth, signInWithPopup, GoogleAuthProvider } from 'firebase/auth';
505
- const auth = getAuth();
506
- const provider = new GoogleAuthProvider();
507
- const result = await signInWithPopup(auth, provider);
508
-
509
- // After (Capacitor Auth Manager)
510
- import { CapacitorAuthManager, AuthProvider } from 'capacitor-auth-manager';
511
- const result = await CapacitorAuthManager.signIn({
512
- provider: AuthProvider.GOOGLE
513
- });
501
+ import type {
502
+ AuthUser,
503
+ AuthResult,
504
+ SignInOptions,
505
+ AuthState,
506
+ AuthProvider,
507
+ AuthCredential,
508
+ } from 'capacitor-auth-manager';
514
509
  ```
515
510
 
516
- ### From Capacitor Google Auth
511
+ ## Platform Notes
517
512
 
518
- ```typescript
519
- // Before
520
- import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
521
- await GoogleAuth.initialize();
522
- const user = await GoogleAuth.signIn();
513
+ ### Web
523
514
 
524
- // After
525
- import { CapacitorAuthManager, AuthProvider } from 'capacitor-auth-manager';
526
- await CapacitorAuthManager.initialize({
527
- providers: [{
528
- provider: AuthProvider.GOOGLE,
529
- options: { clientId: 'YOUR_CLIENT_ID' }
530
- }]
531
- });
532
- const result = await CapacitorAuthManager.signIn({
533
- provider: AuthProvider.GOOGLE
534
- });
535
- ```
515
+ - All providers work without additional setup
516
+ - Some providers (SMS, Magic Link, Email/Password) require backend services
517
+
518
+ ### iOS
536
519
 
537
- ## 📚 Documentation
538
-
539
- For comprehensive documentation, examples, and guides, visit our [Documentation](./docs/README.md):
540
-
541
- ### 🚀 Getting Started
542
- - [Installation Guide](./docs/getting-started/installation.md) - Step-by-step setup instructions
543
- - [Quick Start](./docs/getting-started/quick-start.md) - Get up and running in minutes
544
- - [Platform Setup](./docs/getting-started/platform-setup.md) - Platform-specific configuration
545
-
546
- ### 🔧 API Reference
547
- - [Core API](./docs/api-reference/core-api.md) - Complete method reference
548
- - [Authentication State](./docs/api-reference/auth-state.md) - Understanding auth state
549
- - [Error Handling](./docs/api-reference/error-handling.md) - Handle errors gracefully
550
-
551
- ### 🏢 Provider Guides
552
- - [Google Auth](./docs/providers/google.md) - Google Sign-In implementation
553
- - [Apple Auth](./docs/providers/apple.md) - Sign in with Apple
554
- - [Facebook Auth](./docs/providers/facebook.md) - Facebook Login
555
- - [Microsoft Auth](./docs/providers/microsoft.md) - Microsoft identity platform
556
- - [GitHub Auth](./docs/providers/github.md) - GitHub OAuth
557
- - [Firebase Auth](./docs/providers/firebase.md) - Firebase Authentication
558
- - [More providers...](./docs/providers/) - All 13+ supported providers
559
-
560
- ### 💡 Framework Examples
561
- - [React Integration](./docs/examples/react.md) - Complete React implementation
562
- - [Angular Example](./docs/examples/angular.md) - Angular integration
563
- - [Vue Example](./docs/examples/vue.md) - Vue.js implementation
564
- - [Ionic Example](./docs/examples/ionic.md) - Ionic Framework integration
565
-
566
- ### 📖 Advanced Guides
567
- - [Best Practices](./docs/guides/best-practices.md) - Authentication best practices
568
- - [Security Guide](./docs/guides/security.md) - Security considerations
569
- - [Token Management](./docs/guides/token-management.md) - Handling tokens
570
- - [Multi-Factor Auth](./docs/guides/mfa.md) - Implementing MFA
520
+ - Requires Capacitor for native functionality
521
+ - Biometric auth requires Face ID/Touch ID capability
522
+ - Some providers need URL schemes configuration
523
+
524
+ ### Android
525
+
526
+ - Requires Capacitor for native functionality
527
+ - Biometric auth requires fingerprint hardware
528
+ - Configure `AndroidManifest.xml` for OAuth redirects
571
529
 
572
530
  ## Contributing
573
531
 
574
- Contributions are welcome! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
532
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md).
575
533
 
576
534
  ## License
577
535
 
578
- MIT
536
+ MIT © [Ahsan Mahmood](https://github.com/aoneahsan)
579
537
 
580
538
  ## Support
581
539
 
582
540
  - 📧 Email: aoneahsan@gmail.com
583
541
  - 🐛 Issues: [GitHub Issues](https://github.com/aoneahsan/capacitor-auth-manager/issues)
584
542
  - 💬 Discussions: [GitHub Discussions](https://github.com/aoneahsan/capacitor-auth-manager/discussions)
585
-
586
- ## Credits
587
-
588
- Created by [Ahsan Mahmood](https://aoneahsan.com) - Open source for the community