@umituz/react-native-firebase 1.13.58 → 1.13.60

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 (43) hide show
  1. package/README.md +277 -0
  2. package/package.json +10 -5
  3. package/scripts/README.md +513 -0
  4. package/src/auth/README.md +339 -0
  5. package/src/auth/domain/README.md +264 -0
  6. package/src/auth/domain/errors/README.md +291 -0
  7. package/src/auth/infrastructure/config/README.md +239 -0
  8. package/src/auth/infrastructure/config/initializers/FirebaseAuthInitializer.ts +1 -1
  9. package/src/auth/infrastructure/services/README.md +346 -0
  10. package/src/auth/infrastructure/stores/README.md +407 -0
  11. package/src/auth/infrastructure/stores/auth.store.ts +1 -1
  12. package/src/auth/presentation/hooks/README.md +442 -0
  13. package/src/auth/presentation/hooks/useAnonymousAuth.ts +4 -4
  14. package/src/auth/presentation/hooks/utils/auth-state-change.handler.ts +1 -1
  15. package/src/domain/README.md +628 -0
  16. package/src/firestore/README.md +566 -0
  17. package/src/firestore/domain/README.md +325 -0
  18. package/src/firestore/domain/constants/README.md +332 -0
  19. package/src/firestore/domain/entities/README.md +286 -0
  20. package/src/firestore/domain/errors/README.md +389 -0
  21. package/src/firestore/infrastructure/config/FirestoreClient.ts +1 -1
  22. package/src/firestore/infrastructure/config/README.md +239 -0
  23. package/src/firestore/infrastructure/middleware/README.md +316 -0
  24. package/src/firestore/infrastructure/repositories/BaseRepository.ts +1 -1
  25. package/src/firestore/infrastructure/repositories/README.md +425 -0
  26. package/src/firestore/infrastructure/services/README.md +332 -0
  27. package/src/firestore/infrastructure/services/RequestLoggerService.ts +4 -4
  28. package/src/firestore/types/pagination/README.md +332 -0
  29. package/src/firestore/utils/README.md +574 -0
  30. package/src/firestore/utils/dateUtils/README.md +171 -0
  31. package/src/firestore/utils/document-mapper.helper/README.md +309 -0
  32. package/src/firestore/utils/pagination.helper/README.md +298 -0
  33. package/src/firestore/utils/path-resolver/README.md +277 -0
  34. package/src/firestore/utils/query-builder/README.md +291 -0
  35. package/src/firestore/utils/quota-error-detector/README.md +355 -0
  36. package/src/infrastructure/README.md +408 -0
  37. package/src/infrastructure/config/FirebaseClient.ts +1 -1
  38. package/src/infrastructure/config/README.md +262 -0
  39. package/src/presentation/README.md +556 -0
  40. package/src/storage/README.md +493 -0
  41. package/src/storage/deleter/README.md +370 -0
  42. package/src/storage/types/README.md +313 -0
  43. package/src/storage/uploader/README.md +409 -0
@@ -0,0 +1,407 @@
1
+ # Auth Stores
2
+
3
+ Zustand-based state management for Firebase Authentication.
4
+
5
+ ## Purpose
6
+
7
+ Provides Zustand stores for managing authentication state, user data, and authentication-related UI state with persistence and type safety.
8
+
9
+ ## For AI Agents
10
+
11
+ ### Before Using Auth Stores
12
+
13
+ 1. **ALWAYS** use stores for auth state (never local state)
14
+ 2. **SELECT** specific state slices for performance
15
+ 3. **NEVER** persist transient states (loading, error)
16
+ 4. **USE** actions to update state (never mutate directly)
17
+ 5. **CLEAR** state on logout
18
+
19
+ ### Required Practices
20
+
21
+ 1. **Use stores** for global auth state
22
+ 2. **Select specific slices** - Don't select entire store
23
+ 3. **Use actions** - Call store actions to update state
24
+ 4. **Persist essential data only** - user, isAuthenticated
25
+ 5. **Clear state properly** - Reset state on logout
26
+
27
+ ### Forbidden Practices
28
+
29
+ ## ❌ NEVER
30
+
31
+ - Use local useState for auth state
32
+ - Select entire store (causes unnecessary re-renders)
33
+ - Persist loading and error states
34
+ - Mutate state directly
35
+ - Mix auth state with other state
36
+ - Store sensitive data without encryption
37
+
38
+ ## ⚠️ Avoid
39
+
40
+ - Not using selectors for performance
41
+ - Persisting transient states
42
+ - Complex derived state in store
43
+ - Multiple auth stores
44
+ - Not clearing state on logout
45
+
46
+ ## Usage Strategies
47
+
48
+ ### For Auth State in Components
49
+
50
+ **Strategy:** Use useAuthStore hook with selectors.
51
+
52
+ **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/stores`
53
+
54
+ **When to Use:**
55
+ - Checking authentication status
56
+ - Getting current user
57
+ - Displaying user information
58
+ - Protecting routes
59
+
60
+ **State Properties:**
61
+ - `user: User | null` - Current authenticated user
62
+ - `isAuthenticated: boolean` - Authentication status
63
+ - `isLoading: boolean` - Loading state
64
+ - `error: Error | null` - Error state
65
+
66
+ **Basic Usage:**
67
+ 1. Import useAuthStore
68
+ 2. Destructure needed properties
69
+ 3. Check isAuthenticated before showing protected content
70
+ 4. Show loading indicator during auth check
71
+
72
+ ### For Performance Optimization
73
+
74
+ **Strategy:** Select specific state slices only.
75
+
76
+ **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/stores`
77
+
78
+ **When to Use:**
79
+ - Only need user property
80
+ - Only need authentication status
81
+ - Preventing unnecessary re-renders
82
+ - Large components
83
+
84
+ **Selector Usage:**
85
+ - Select single property: `useAuthStore(state => state.user)`
86
+ - Select multiple: `useAuthStore(state => ({ user: state.user, isLoading: state.isLoading }))`
87
+ - Never select entire store: `const store = useAuthStore()` (bad practice)
88
+
89
+ **Benefits:**
90
+ - Only re-render when selected properties change
91
+ - Better performance
92
+ - More predictable behavior
93
+ - Cleaner code
94
+
95
+ ### For Auth Provider
96
+
97
+ **Strategy:** Initialize auth state on app startup.
98
+
99
+ **Import From:** `@umituz/react-native-firebase/auth` and Firebase Auth
100
+
101
+ **When to Use:**
102
+ - App initialization
103
+ - Root component
104
+ - Auth state sync
105
+
106
+ **Implementation Strategy:**
107
+ 1. Create AuthProvider component
108
+ 2. Use onAuthStateChanged listener
109
+ 3. Update store with setUser and setLoading
110
+ 4. Unsubscribe listener on unmount
111
+ 5. Wrap app root with provider
112
+
113
+ **Provider Responsibilities:**
114
+ - Sync Firebase Auth state with store
115
+ - Set loading state during initial check
116
+ - Clean up listeners on unmount
117
+ - Handle auth state changes
118
+
119
+ ### For Protected Routes
120
+
121
+ **Strategy:** Check auth state before rendering protected content.
122
+
123
+ **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/stores`
124
+
125
+ **When to Use:**
126
+ - Pages requiring authentication
127
+ - User profile pages
128
+ - Dashboard and settings
129
+ - Protected features
130
+
131
+ **Route Protection Flow:**
132
+ 1. Component mounts
133
+ 2. Check isLoading state
134
+ 3. If loading, show spinner
135
+ 4. If authenticated, show protected content
136
+ 5. If not authenticated, redirect to login
137
+ 6. Handle anonymous users appropriately
138
+
139
+ ### For Logout
140
+
141
+ **Strategy:** Use store logout action to sign out user.
142
+
143
+ **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/stores`
144
+
145
+ **When to Use:**
146
+ - User clicks logout button
147
+ - Session timeout
148
+ - Manual sign-out
149
+
150
+ **Logout Flow:**
151
+ 1. Call logout() action from store
152
+ 2. Sign out from Firebase Auth
153
+ 3. Clear all auth state
154
+ 4. Navigation handled by auth state change
155
+
156
+ ### For Error Display
157
+
158
+ **Strategy:** Show error messages from store state.
159
+
160
+ **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/stores`
161
+
162
+ **When to Use:**
163
+ - Displaying auth errors
164
+ - Showing error banners
165
+ - Error toasts/messages
166
+
167
+ **Error Display Strategy:**
168
+ 1. Select error from store
169
+ 2. Show error banner if error exists
170
+ 3. Call clearError() after displaying
171
+ 4. Use useEffect for auto-clear
172
+
173
+ ## Store API
174
+
175
+ ### State Properties
176
+
177
+ **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/stores`
178
+
179
+ **Properties:**
180
+ - `user: User | null` - Current authenticated user
181
+ - `isAuthenticated: boolean` - User logged in status
182
+ - `isLoading: boolean` - Auth state loading
183
+ - `error: Error | null` - Auth error
184
+
185
+ **Persistence:**
186
+ - Persisted: user, isAuthenticated
187
+ - Not persisted: isLoading, error
188
+
189
+ ### Actions
190
+
191
+ **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/stores`
192
+
193
+ **Available Actions:**
194
+ - `setUser(user: User | null)` - Set current user
195
+ - `setLoading(loading: boolean)` - Set loading state
196
+ - `setError(error: Error | null)` - Set error
197
+ - `clearError()` - Clear error
198
+ - `logout()` - Sign out user
199
+
200
+ **Usage:**
201
+ - Call actions to update state
202
+ - Never mutate state directly
203
+ - Actions handle Firebase operations
204
+ - Use logout() for sign-out
205
+
206
+ ## Persistence Strategy
207
+
208
+ ### Persist Configuration
209
+
210
+ **Import From:** Zustand persist middleware
211
+
212
+ **Strategy:** Persist only essential auth data.
213
+
214
+ **Persisted State:**
215
+ - `user` - User object
216
+ - `isAuthenticated` - Auth status
217
+
218
+ **Not Persisted:**
219
+ - `isLoading` - Transient loading state
220
+ - `error` - Transient error state
221
+
222
+ **Benefits:**
223
+ - Faster app startup (user already loaded)
224
+ - Better UX (no loading flash)
225
+ - Clean state after reload
226
+ - No stale transient states
227
+
228
+ **Storage Name:** 'auth-storage'
229
+
230
+ ## Common Mistakes to Avoid
231
+
232
+ 1. ❌ Using useState for auth state
233
+ - ✅ Always use useAuthStore
234
+
235
+ 2. ❌ Selecting entire store
236
+ - ✅ Select specific properties with selectors
237
+
238
+ 3. ❌ Persisting loading/error states
239
+ - ✅ Only persist user and isAuthenticated
240
+
241
+ 4. ❌ Not clearing errors
242
+ - ✅ Call clearError() after displaying
243
+
244
+ 5. ❌ Mutating state directly
245
+ - ✅ Use store actions
246
+
247
+ 6. ❌ Not using selectors for performance
248
+ - ✅ Always select specific slices
249
+
250
+ ## AI Agent Instructions
251
+
252
+ ### When Using Auth Store in Component
253
+
254
+ 1. Import useAuthStore from auth
255
+ 2. Select specific properties needed
256
+ 3. Check isAuthenticated before showing content
257
+ 4. Show loading state during auth check
258
+ 5. Handle errors appropriately
259
+
260
+ ### When Creating Auth Provider
261
+
262
+ 1. Use onAuthStateChanged listener
263
+ 2. Update store on auth changes
264
+ 3. Set loading state appropriately
265
+ 4. Clean up listener on unmount
266
+ 5. Wrap app root with provider
267
+
268
+ ### When Protecting Route
269
+
270
+ 1. Select isAuthenticated and isLoading
271
+ 2. Show loading while checking
272
+ 3. Redirect to login if not authenticated
273
+ 4. Show protected content if authenticated
274
+ 5. Handle anonymous users appropriately
275
+
276
+ ### When Implementing Logout
277
+
278
+ 1. Call logout() action from store
279
+ 2. Handle Firebase sign-out
280
+ 3. Clear all auth state
281
+ 4. Navigate to login screen
282
+ 5. Handle errors gracefully
283
+
284
+ ## Code Quality Standards
285
+
286
+ ### TypeScript
287
+
288
+ - Export AuthState interface
289
+ - Type all store properties
290
+ - Type all actions
291
+ - Use proper User type from Firebase
292
+ - Never use `any`
293
+
294
+ ### Performance
295
+
296
+ - Always use selectors
297
+ - Never select entire store
298
+ - Select only what's needed
299
+ - Use shallow comparison for objects
300
+ - Optimize re-renders
301
+
302
+ ### State Management
303
+
304
+ - One source of truth (store)
305
+ - Actions for state updates
306
+ - No direct mutations
307
+ - Clear state on logout
308
+ - Persist only essential data
309
+
310
+ ## Performance Considerations
311
+
312
+ ### Selector Performance
313
+
314
+ **Why Selectors:**
315
+ - Prevents unnecessary re-renders
316
+ - Component only updates when selected properties change
317
+ - Better performance for large components
318
+ - More predictable behavior
319
+
320
+ **Selector Patterns:**
321
+ - Single property: `state => state.user`
322
+ - Multiple properties: `state => ({ user, isLoading })`
323
+ - Computed: `state => state.user?.email`
324
+
325
+ ### Re-render Optimization
326
+
327
+ **Selector Strategy:**
328
+
329
+ **Good Practice:** Select specific state properties
330
+ - Use: `useAuthStore(state => state.user)`
331
+ - Only re-renders when user changes
332
+ - Minimizes re-renders
333
+
334
+ **Bad Practice:** Select entire store
335
+ - Avoid: `useAuthStore()` without selector
336
+ - Re-renders on any state change
337
+ - Causes unnecessary re-renders
338
+
339
+ **Selector Usage Rules:**
340
+ - Use selectors to extract specific state
341
+ - Only re-renders when selected state changes
342
+ - Avoid grabbing entire store
343
+ - Use shallow equality for objects
344
+
345
+ ## Related Documentation
346
+
347
+ - [Auth Module README](../../README.md)
348
+ - [Auth Services README](../services/README.md)
349
+ - [Auth Hooks README](../../presentation/hooks/README.md)
350
+ - [Zustand Documentation](https://zustand-demo.pmnd.rs/)
351
+
352
+ ## Architecture
353
+
354
+ ### Store Layer (Infrastructure)
355
+
356
+ **Responsibilities:**
357
+ - Global auth state
358
+ - State persistence
359
+ - State updates via actions
360
+ - Auth state sync with Firebase
361
+
362
+ **Dependencies:**
363
+ - Zustand for state management
364
+ - Zustand persist middleware
365
+ - Firebase Auth SDK (in actions)
366
+
367
+ **Usage Pattern:**
368
+ - UI components use hooks
369
+ - Hooks call store actions
370
+ - Actions update state
371
+ - State persists across sessions
372
+
373
+ ## API Reference
374
+
375
+ ### Main Hook
376
+
377
+ **Import Path:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/stores`
378
+
379
+ **Hook:** `useAuthStore(selector?)`
380
+
381
+ **Returns:**
382
+ - Full store state (if no selector)
383
+ - Selected state slice (if selector provided)
384
+
385
+ ### State Properties
386
+
387
+ | Property | Type | Persisted | Description |
388
+ |----------|------|-----------|-------------|
389
+ | `user` | `User \| null` | Yes | Current authenticated user |
390
+ | `isAuthenticated` | `boolean` | Yes | Authentication status |
391
+ | `isLoading` | `boolean` | No | Loading state |
392
+ | `error` | `Error \| null` | No | Error state |
393
+
394
+ ### Actions
395
+
396
+ | Action | Parameters | Description |
397
+ |--------|------------|-------------|
398
+ | `setUser` | `(user: User \| null)` | Set current user |
399
+ | `setLoading` | `(loading: boolean)` | Set loading state |
400
+ | `setError` | `(error: Error \| null)` | Set error |
401
+ | `clearError` | `()` | Clear error |
402
+ | `logout` | `()` | Sign out user |
403
+
404
+ ---
405
+
406
+ **Last Updated:** 2025-01-08
407
+ **Maintainer:** Auth Module Team
@@ -47,7 +47,7 @@ export const useFirebaseAuthStore = createStore<AuthState, AuthActions>({
47
47
 
48
48
  unsubscribe = onAuthStateChanged(auth, (currentUser: User | null) => {
49
49
  if (typeof __DEV__ !== "undefined" && __DEV__) {
50
- // eslint-disable-next-line no-console
50
+
51
51
  console.log(
52
52
  "[FirebaseAuthStore] Auth state changed:",
53
53
  currentUser?.uid || "null"