@umituz/react-native-firebase 1.13.58 → 1.13.59
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/README.md +277 -0
- package/package.json +1 -1
- package/scripts/README.md +513 -0
- package/src/auth/README.md +339 -0
- package/src/auth/domain/README.md +264 -0
- package/src/auth/domain/errors/README.md +291 -0
- package/src/auth/infrastructure/config/README.md +239 -0
- package/src/auth/infrastructure/services/README.md +346 -0
- package/src/auth/infrastructure/stores/README.md +407 -0
- package/src/auth/presentation/hooks/README.md +442 -0
- package/src/domain/README.md +628 -0
- package/src/firestore/README.md +566 -0
- package/src/firestore/domain/README.md +325 -0
- package/src/firestore/domain/constants/README.md +332 -0
- package/src/firestore/domain/entities/README.md +286 -0
- package/src/firestore/domain/errors/README.md +389 -0
- package/src/firestore/infrastructure/config/README.md +239 -0
- package/src/firestore/infrastructure/middleware/README.md +316 -0
- package/src/firestore/infrastructure/repositories/README.md +425 -0
- package/src/firestore/infrastructure/services/README.md +332 -0
- package/src/firestore/types/pagination/README.md +332 -0
- package/src/firestore/utils/README.md +574 -0
- package/src/firestore/utils/dateUtils/README.md +171 -0
- package/src/firestore/utils/document-mapper.helper/README.md +309 -0
- package/src/firestore/utils/pagination.helper/README.md +298 -0
- package/src/firestore/utils/path-resolver/README.md +277 -0
- package/src/firestore/utils/query-builder/README.md +291 -0
- package/src/firestore/utils/quota-error-detector/README.md +355 -0
- package/src/infrastructure/README.md +408 -0
- package/src/infrastructure/config/README.md +262 -0
- package/src/presentation/README.md +556 -0
- package/src/storage/README.md +493 -0
- package/src/storage/deleter/README.md +370 -0
- package/src/storage/types/README.md +313 -0
- package/src/storage/uploader/README.md +409 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
# Auth Hooks
|
|
2
|
+
|
|
3
|
+
React hooks for Firebase Authentication operations with state management and error handling.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides React hooks for authentication operations (Anonymous, Google, Apple, Email) with automatic state management, error handling, and loading states.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Auth Hooks
|
|
12
|
+
|
|
13
|
+
1. **ALWAYS** use hooks for auth state in UI components
|
|
14
|
+
2. **NEVER** use Firebase Auth SDK directly in components
|
|
15
|
+
3. **HANDLE** loading, error, and authentication states
|
|
16
|
+
4. **PROVIDE** user feedback for auth operations
|
|
17
|
+
5. **CLEAN UP** auth listeners on unmount
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Use hooks** for all auth operations in UI
|
|
22
|
+
2. **Handle loading states** - show indicators during auth operations
|
|
23
|
+
3. **Handle errors** - display user-friendly error messages
|
|
24
|
+
4. **Check isAuthenticated** before accessing protected features
|
|
25
|
+
5. **Use auth guards** for protected routes
|
|
26
|
+
|
|
27
|
+
### Forbidden Practices
|
|
28
|
+
|
|
29
|
+
## ❌ NEVER
|
|
30
|
+
|
|
31
|
+
- Use Firebase Auth SDK directly in UI components
|
|
32
|
+
- Access Firebase functions without hooks
|
|
33
|
+
- Ignore loading states
|
|
34
|
+
- Ignore auth errors
|
|
35
|
+
- Mix auth providers incorrectly
|
|
36
|
+
- Hardcode auth credentials
|
|
37
|
+
|
|
38
|
+
## ⚠️ Avoid
|
|
39
|
+
|
|
40
|
+
- Not handling loading states (poor UX)
|
|
41
|
+
- Not showing error messages to users
|
|
42
|
+
- Multiple simultaneous auth operations
|
|
43
|
+
- Not cleaning up listeners
|
|
44
|
+
- Complicated auth logic in components
|
|
45
|
+
|
|
46
|
+
## Usage Strategies
|
|
47
|
+
|
|
48
|
+
### For General Authentication
|
|
49
|
+
|
|
50
|
+
**Hook:** `useFirebaseAuth()`
|
|
51
|
+
|
|
52
|
+
**Import From:** `src/auth/presentation/hooks`
|
|
53
|
+
|
|
54
|
+
**When to Use:**
|
|
55
|
+
- Checking if user is authenticated
|
|
56
|
+
- Getting current user information
|
|
57
|
+
- Global authentication state
|
|
58
|
+
- Protected route components
|
|
59
|
+
|
|
60
|
+
**State Provided:**
|
|
61
|
+
- `user` - Current authenticated user or null
|
|
62
|
+
- `isLoading` - True during auth check
|
|
63
|
+
- `isAuthenticated` - True if user logged in
|
|
64
|
+
- `error` - Any authentication error
|
|
65
|
+
|
|
66
|
+
**Usage Pattern:**
|
|
67
|
+
1. Import hook from auth presentation hooks
|
|
68
|
+
2. Call hook in component
|
|
69
|
+
3. Check isAuthenticated before showing protected content
|
|
70
|
+
4. Show loading indicator during auth check
|
|
71
|
+
5. Handle errors appropriately
|
|
72
|
+
|
|
73
|
+
### For Anonymous Authentication
|
|
74
|
+
|
|
75
|
+
**Hook:** `useAnonymousAuth()`
|
|
76
|
+
|
|
77
|
+
**Import From:** `src/auth/presentation/hooks`
|
|
78
|
+
|
|
79
|
+
**When to Use:**
|
|
80
|
+
- Guest access to application
|
|
81
|
+
- Temporary user sessions
|
|
82
|
+
- Quick onboarding
|
|
83
|
+
- Testing without registration
|
|
84
|
+
|
|
85
|
+
**Methods Provided:**
|
|
86
|
+
- `signIn()` - Create anonymous user
|
|
87
|
+
- `signOut()` - Sign out anonymous user
|
|
88
|
+
|
|
89
|
+
**Strategy:**
|
|
90
|
+
- Use for quick app tryout
|
|
91
|
+
- Prompt to upgrade to permanent account
|
|
92
|
+
- Track anonymous user session
|
|
93
|
+
- Migrate to permanent account when upgrading
|
|
94
|
+
|
|
95
|
+
**User Flow:**
|
|
96
|
+
1. User launches app
|
|
97
|
+
2. Call signIn() automatically or on user action
|
|
98
|
+
3. Access app features with limited functionality
|
|
99
|
+
4. Prompt to create permanent account
|
|
100
|
+
5. Migrate anonymous account to permanent
|
|
101
|
+
|
|
102
|
+
### For Social Authentication
|
|
103
|
+
|
|
104
|
+
**Hook:** `useSocialAuth(config)`
|
|
105
|
+
|
|
106
|
+
**Import From:** `src/auth/presentation/hooks`
|
|
107
|
+
|
|
108
|
+
**When to Use:**
|
|
109
|
+
- Google OAuth sign-in
|
|
110
|
+
- Apple ID sign-in (iOS only)
|
|
111
|
+
- Primary authentication method
|
|
112
|
+
- Account linking
|
|
113
|
+
|
|
114
|
+
**Configuration:**
|
|
115
|
+
- Pass provider configuration (Google Client ID, etc.)
|
|
116
|
+
- Apple automatically skipped on Android
|
|
117
|
+
- Handle sign-in errors gracefully
|
|
118
|
+
|
|
119
|
+
**Methods Provided:**
|
|
120
|
+
- `signInWithGoogle()` - Google OAuth
|
|
121
|
+
- `signInWithApple()` - Apple ID (iOS)
|
|
122
|
+
- `signOut()` - Sign out
|
|
123
|
+
|
|
124
|
+
**Strategy:**
|
|
125
|
+
- Use Google as primary auth method
|
|
126
|
+
- Use Apple on iOS as alternative
|
|
127
|
+
- Handle sign-in errors with user messages
|
|
128
|
+
- Implement reauthentication when needed
|
|
129
|
+
|
|
130
|
+
### For Protected Routes
|
|
131
|
+
|
|
132
|
+
**Strategy:** Use auth guard service to protect routes.
|
|
133
|
+
|
|
134
|
+
**Import From:** `src/auth/presentation/hooks` and infrastructure
|
|
135
|
+
|
|
136
|
+
**When to Use:**
|
|
137
|
+
- Pages requiring authentication
|
|
138
|
+
- User profile pages
|
|
139
|
+
- Dashboard and settings
|
|
140
|
+
- Any protected feature
|
|
141
|
+
|
|
142
|
+
**Implementation:**
|
|
143
|
+
1. Use `useFirebaseAuth()` hook
|
|
144
|
+
2. Check `isAuthenticated` state
|
|
145
|
+
3. Redirect to login if not authenticated
|
|
146
|
+
4. Show loading state during check
|
|
147
|
+
5. Allow anonymous users if appropriate
|
|
148
|
+
|
|
149
|
+
**Route Protection Flow:**
|
|
150
|
+
1. Component mounts
|
|
151
|
+
2. Hook checks auth state
|
|
152
|
+
3. If loading, show spinner
|
|
153
|
+
4. If authenticated, show protected content
|
|
154
|
+
5. If not authenticated, redirect to login
|
|
155
|
+
|
|
156
|
+
### For Account Deletion
|
|
157
|
+
|
|
158
|
+
**Strategy:** Use delete account functionality with proper cleanup.
|
|
159
|
+
|
|
160
|
+
**Import From:** `src/auth` (hooks and infrastructure)
|
|
161
|
+
|
|
162
|
+
**When to Use:**
|
|
163
|
+
- User requests account deletion
|
|
164
|
+
- GDPR compliance
|
|
165
|
+
- User data cleanup
|
|
166
|
+
- Testing
|
|
167
|
+
|
|
168
|
+
**Implementation:**
|
|
169
|
+
1. Confirm deletion with user
|
|
170
|
+
2. Delete Auth account
|
|
171
|
+
3. Clean up Firestore data (automatic)
|
|
172
|
+
4. Clean up Storage files (manual if needed)
|
|
173
|
+
5. Sign out and redirect
|
|
174
|
+
|
|
175
|
+
**Cleanup Considerations:**
|
|
176
|
+
- Auth account deleted automatically
|
|
177
|
+
- Firestore user data deleted by service
|
|
178
|
+
- Storage files may need manual cleanup
|
|
179
|
+
- Handle errors appropriately
|
|
180
|
+
|
|
181
|
+
## Hook Reference
|
|
182
|
+
|
|
183
|
+
### useFirebaseAuth()
|
|
184
|
+
|
|
185
|
+
**Import From:** `src/auth/presentation/hooks`
|
|
186
|
+
|
|
187
|
+
**Purpose:** General authentication state and user information
|
|
188
|
+
|
|
189
|
+
**Returns:**
|
|
190
|
+
- `user: User | null` - Current authenticated user
|
|
191
|
+
- `isLoading: boolean` - Auth state loading
|
|
192
|
+
- `isAuthenticated: boolean` - User logged in
|
|
193
|
+
- `error: Error | null` - Auth error
|
|
194
|
+
|
|
195
|
+
**Use For:**
|
|
196
|
+
- Checking authentication status
|
|
197
|
+
- Getting user info
|
|
198
|
+
- Protecting routes
|
|
199
|
+
- Global auth state
|
|
200
|
+
|
|
201
|
+
### useAnonymousAuth()
|
|
202
|
+
|
|
203
|
+
**Import From:** `src/auth/presentation/hooks`
|
|
204
|
+
|
|
205
|
+
**Purpose:** Anonymous (guest) authentication
|
|
206
|
+
|
|
207
|
+
**Returns:**
|
|
208
|
+
- `user: User | null` - Anonymous user
|
|
209
|
+
- `isLoading: boolean` - Operation loading
|
|
210
|
+
- `isAuthenticated: boolean` - Guest logged in
|
|
211
|
+
- `error: Error | null` - Auth error
|
|
212
|
+
- `signIn: () => Promise<void>` - Sign in as guest
|
|
213
|
+
- `signOut: () => Promise<void>` - Sign out
|
|
214
|
+
|
|
215
|
+
**Use For:**
|
|
216
|
+
- Guest access
|
|
217
|
+
- Temporary sessions
|
|
218
|
+
- Quick onboarding
|
|
219
|
+
- Testing
|
|
220
|
+
|
|
221
|
+
### useSocialAuth(config)
|
|
222
|
+
|
|
223
|
+
**Import From:** `src/auth/presentation/hooks`
|
|
224
|
+
|
|
225
|
+
**Purpose:** Social authentication (Google, Apple)
|
|
226
|
+
|
|
227
|
+
**Configuration:**
|
|
228
|
+
- `googleClientId?: string` - Google OAuth Client ID
|
|
229
|
+
- Apple ID auto-configured (iOS only)
|
|
230
|
+
|
|
231
|
+
**Returns:**
|
|
232
|
+
- `user: User | null` - Authenticated user
|
|
233
|
+
- `isLoading: boolean` - Operation loading
|
|
234
|
+
- `isAuthenticated: boolean` - User logged in
|
|
235
|
+
- `error: Error | null` - Auth error
|
|
236
|
+
- `signInWithGoogle: () => Promise<void>` - Google sign-in
|
|
237
|
+
- `signInWithApple: () => Promise<void>` - Apple sign-in (iOS)
|
|
238
|
+
- `signOut: () => Promise<void>` - Sign out
|
|
239
|
+
|
|
240
|
+
**Use For:**
|
|
241
|
+
- Primary authentication
|
|
242
|
+
- Social sign-in
|
|
243
|
+
- Account linking
|
|
244
|
+
- Reauthentication
|
|
245
|
+
|
|
246
|
+
## State Management
|
|
247
|
+
|
|
248
|
+
### Loading States
|
|
249
|
+
|
|
250
|
+
**Strategy:** Always show loading indicators during auth operations.
|
|
251
|
+
|
|
252
|
+
**Loading Scenarios:**
|
|
253
|
+
- Initial auth check (app startup)
|
|
254
|
+
- Sign in operations
|
|
255
|
+
- Sign out operations
|
|
256
|
+
- Account deletion
|
|
257
|
+
|
|
258
|
+
**UX Guidelines:**
|
|
259
|
+
- Show spinner/indicator during auth operations
|
|
260
|
+
- Disable auth buttons during loading
|
|
261
|
+
- Don't block UI for initial auth check
|
|
262
|
+
- Clear indication of operation in progress
|
|
263
|
+
|
|
264
|
+
### Error Handling
|
|
265
|
+
|
|
266
|
+
**Strategy:** Handle all auth errors with user-friendly messages.
|
|
267
|
+
|
|
268
|
+
**Error Types:**
|
|
269
|
+
- Network errors
|
|
270
|
+
- Auth provider errors
|
|
271
|
+
- Configuration errors
|
|
272
|
+
- User cancellation
|
|
273
|
+
|
|
274
|
+
**Error Handling Approach:**
|
|
275
|
+
1. Catch errors in hook
|
|
276
|
+
2. Provide in `error` state
|
|
277
|
+
3. Display user-friendly message
|
|
278
|
+
4. Allow retry if appropriate
|
|
279
|
+
5. Log technical errors for debugging
|
|
280
|
+
|
|
281
|
+
### Authentication State
|
|
282
|
+
|
|
283
|
+
**States:**
|
|
284
|
+
1. **Loading** - Initial auth check in progress
|
|
285
|
+
2. **Authenticated** - User logged in
|
|
286
|
+
3. **Not Authenticated** - User logged out
|
|
287
|
+
4. **Error** - Auth operation failed
|
|
288
|
+
|
|
289
|
+
**State Flow:**
|
|
290
|
+
- Loading → Authenticated (success)
|
|
291
|
+
- Loading → Not Authenticated (no user)
|
|
292
|
+
- Any → Error (operation failed)
|
|
293
|
+
|
|
294
|
+
## Common Mistakes to Avoid
|
|
295
|
+
|
|
296
|
+
1. ❌ Using Firebase Auth SDK directly in components
|
|
297
|
+
- ✅ Always use auth hooks
|
|
298
|
+
|
|
299
|
+
2. ❌ Not handling loading states
|
|
300
|
+
- ✅ Show loading indicators
|
|
301
|
+
|
|
302
|
+
3. ❌ Ignoring auth errors
|
|
303
|
+
- ✅ Display error messages to users
|
|
304
|
+
|
|
305
|
+
4. ❌ Hardcoding auth credentials
|
|
306
|
+
- ✅ Use environment variables
|
|
307
|
+
|
|
308
|
+
5. ❌ Not protecting routes
|
|
309
|
+
- ✅ Use auth guards
|
|
310
|
+
|
|
311
|
+
## AI Agent Instructions
|
|
312
|
+
|
|
313
|
+
### When Creating Auth Hook
|
|
314
|
+
|
|
315
|
+
1. Import from `src/auth/presentation/hooks`
|
|
316
|
+
2. Use appropriate hook for auth type
|
|
317
|
+
3. Handle all states (loading, error, authenticated)
|
|
318
|
+
4. Provide user feedback
|
|
319
|
+
5. Clean up on unmount
|
|
320
|
+
|
|
321
|
+
### When Protecting Route
|
|
322
|
+
|
|
323
|
+
1. Use `useFirebaseAuth()` hook
|
|
324
|
+
2. Check `isAuthenticated` before showing content
|
|
325
|
+
3. Redirect to login if not authenticated
|
|
326
|
+
4. Show loading state during check
|
|
327
|
+
5. Handle anonymous users appropriately
|
|
328
|
+
|
|
329
|
+
### When Adding Auth Provider
|
|
330
|
+
|
|
331
|
+
1. Check existing auth hooks first
|
|
332
|
+
2. Follow hook patterns
|
|
333
|
+
3. Return consistent interface
|
|
334
|
+
4. Handle loading and error states
|
|
335
|
+
5. Update this README
|
|
336
|
+
|
|
337
|
+
## Code Quality Standards
|
|
338
|
+
|
|
339
|
+
### TypeScript
|
|
340
|
+
|
|
341
|
+
- All hooks properly typed
|
|
342
|
+
- Return interfaces defined
|
|
343
|
+
- User type from Firebase Auth
|
|
344
|
+
- Error type properly handled
|
|
345
|
+
|
|
346
|
+
### File Organization
|
|
347
|
+
|
|
348
|
+
- One hook per file
|
|
349
|
+
- Hooks in `presentation/hooks/`
|
|
350
|
+
- Services in `infrastructure/services/`
|
|
351
|
+
- Stores in `infrastructure/stores/`
|
|
352
|
+
|
|
353
|
+
### Error Handling
|
|
354
|
+
|
|
355
|
+
- Never throw from hooks
|
|
356
|
+
- Return errors in state
|
|
357
|
+
- Provide error context
|
|
358
|
+
- Handle edge cases
|
|
359
|
+
|
|
360
|
+
## Related Documentation
|
|
361
|
+
|
|
362
|
+
- [Auth Module README](../../README.md)
|
|
363
|
+
- [Auth Services README](../../infrastructure/services/README.md)
|
|
364
|
+
- [Auth Stores README](../../infrastructure/stores/README.md)
|
|
365
|
+
- [Auth Config README](../../infrastructure/config/README.md)
|
|
366
|
+
|
|
367
|
+
## Architecture
|
|
368
|
+
|
|
369
|
+
### Hook Layer (Presentation)
|
|
370
|
+
|
|
371
|
+
**Responsibilities:**
|
|
372
|
+
- UI state management
|
|
373
|
+
- User interactions
|
|
374
|
+
- Loading/error states
|
|
375
|
+
- Component integration
|
|
376
|
+
|
|
377
|
+
**Dependencies:**
|
|
378
|
+
- Uses services (infrastructure layer)
|
|
379
|
+
- Uses stores (state management)
|
|
380
|
+
- Never imports Firebase directly
|
|
381
|
+
|
|
382
|
+
### Service Layer (Infrastructure)
|
|
383
|
+
|
|
384
|
+
**Responsibilities:**
|
|
385
|
+
- Firebase Auth operations
|
|
386
|
+
- Business logic
|
|
387
|
+
- Error transformation
|
|
388
|
+
- State updates
|
|
389
|
+
|
|
390
|
+
### Store Layer (Infrastructure)
|
|
391
|
+
|
|
392
|
+
**Responsibilities:**
|
|
393
|
+
- Global auth state
|
|
394
|
+
- State persistence
|
|
395
|
+
- State updates
|
|
396
|
+
|
|
397
|
+
## Migration Guide
|
|
398
|
+
|
|
399
|
+
### From Direct Firebase Auth
|
|
400
|
+
|
|
401
|
+
**Don't Use:**
|
|
402
|
+
- Importing `getAuth` from firebase/auth
|
|
403
|
+
- Manual auth state listeners
|
|
404
|
+
- Direct signInWithPopup calls
|
|
405
|
+
- Manual state management
|
|
406
|
+
|
|
407
|
+
**Use Instead:**
|
|
408
|
+
- `useFirebaseAuth()` for auth state
|
|
409
|
+
- `useAnonymousAuth()` for guest access
|
|
410
|
+
- `useSocialAuth()` for social sign-in
|
|
411
|
+
- Hooks handle everything
|
|
412
|
+
|
|
413
|
+
## Best Practices
|
|
414
|
+
|
|
415
|
+
### Component Integration
|
|
416
|
+
|
|
417
|
+
1. Import hooks from `@umituz/react-native-firebase/auth`
|
|
418
|
+
2. Call hooks at component top level
|
|
419
|
+
3. Destructure returned values
|
|
420
|
+
4. Handle all states
|
|
421
|
+
5. Never use Firebase SDK in component
|
|
422
|
+
|
|
423
|
+
### User Experience
|
|
424
|
+
|
|
425
|
+
1. Show loading indicators
|
|
426
|
+
2. Display clear error messages
|
|
427
|
+
3. Disable buttons during operations
|
|
428
|
+
4. Provide sign-out option
|
|
429
|
+
5. Handle anonymous users appropriately
|
|
430
|
+
|
|
431
|
+
### Security
|
|
432
|
+
|
|
433
|
+
1. Never expose auth credentials
|
|
434
|
+
2. Use environment variables for config
|
|
435
|
+
3. Implement proper route protection
|
|
436
|
+
4. Handle auth errors gracefully
|
|
437
|
+
5. Log security-relevant events
|
|
438
|
+
|
|
439
|
+
---
|
|
440
|
+
|
|
441
|
+
**Last Updated:** 2025-01-08
|
|
442
|
+
**Maintainer:** Auth Module Team
|