@umituz/react-native-firebase 1.14.4 → 2.0.1

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 (132) hide show
  1. package/package.json +1 -1
  2. package/src/domains/account-deletion/index.ts +28 -0
  3. package/src/{auth → domains/account-deletion}/infrastructure/services/account-deletion.service.ts +4 -4
  4. package/src/{auth → domains/account-deletion}/infrastructure/services/reauthentication.service.ts +5 -5
  5. package/src/{auth → domains/auth}/index.ts +0 -21
  6. package/src/{auth → domains/auth}/infrastructure/config/FirebaseAuthClient.ts +2 -2
  7. package/src/{auth → domains/auth}/infrastructure/services/apple-auth.service.ts +1 -1
  8. package/src/{auth → domains/auth}/infrastructure/services/auth-listener.service.ts +2 -2
  9. package/src/{auth → domains/auth}/infrastructure/services/auth-utils.service.ts +1 -1
  10. package/src/{auth → domains/auth}/infrastructure/services/base/base-auth.service.ts +1 -1
  11. package/src/{auth → domains/auth}/infrastructure/services/email-auth.service.ts +1 -1
  12. package/src/{auth → domains/auth}/infrastructure/services/google-auth.service.ts +2 -2
  13. package/src/{auth → domains/auth}/infrastructure/services/password.service.ts +1 -1
  14. package/src/{firestore → domains/firestore}/domain/errors/FirebaseFirestoreError.ts +1 -1
  15. package/src/{firestore → domains/firestore}/infrastructure/config/FirestoreClient.ts +2 -2
  16. package/src/{firestore → domains/firestore}/infrastructure/services/RequestLoggerService.ts +1 -1
  17. package/src/{firestore → domains/firestore}/utils/quota-error-detector.util.ts +1 -1
  18. package/src/{firestore → domains/firestore}/utils/transaction/transaction.util.ts +1 -1
  19. package/src/index.ts +12 -11
  20. package/src/init/createFirebaseInitModule.ts +1 -1
  21. package/src/{domain → shared/domain}/utils/credential.util.ts +1 -1
  22. package/src/{infrastructure → shared/infrastructure}/config/clients/FirebaseClientSingleton.ts +1 -1
  23. package/src/auth/domain/errors/README.md +0 -291
  24. package/src/auth/infrastructure/config/README.md +0 -239
  25. package/src/auth/infrastructure/services/README.md +0 -346
  26. package/src/domain/README.md +0 -628
  27. package/src/firestore/domain/README.md +0 -325
  28. package/src/firestore/domain/constants/README.md +0 -332
  29. package/src/firestore/domain/entities/README.md +0 -286
  30. package/src/firestore/domain/errors/README.md +0 -389
  31. package/src/firestore/infrastructure/config/README.md +0 -239
  32. package/src/firestore/infrastructure/middleware/README.md +0 -316
  33. package/src/firestore/infrastructure/repositories/README.md +0 -425
  34. package/src/firestore/infrastructure/services/README.md +0 -332
  35. package/src/firestore/types/pagination/README.md +0 -332
  36. package/src/firestore/utils/README.md +0 -574
  37. package/src/firestore/utils/dateUtils/README.md +0 -171
  38. package/src/firestore/utils/document-mapper.helper/README.md +0 -309
  39. package/src/firestore/utils/pagination.helper/README.md +0 -298
  40. package/src/firestore/utils/query-builder/README.md +0 -291
  41. package/src/infrastructure/README.md +0 -408
  42. package/src/infrastructure/config/README.md +0 -262
  43. package/src/presentation/README.md +0 -556
  44. /package/src/{auth/infrastructure/services → domains/account-deletion/application/ports}/reauthentication.types.ts +0 -0
  45. /package/src/{auth → domains/auth}/domain/entities/AnonymousUser.ts +0 -0
  46. /package/src/{auth → domains/auth}/domain/errors/FirebaseAuthError.ts +0 -0
  47. /package/src/{auth → domains/auth}/domain/value-objects/FirebaseAuthConfig.ts +0 -0
  48. /package/src/{auth → domains/auth}/infrastructure/config/initializers/FirebaseAuthInitializer.ts +0 -0
  49. /package/src/{auth → domains/auth}/infrastructure/services/anonymous-auth.service.ts +0 -0
  50. /package/src/{auth → domains/auth}/infrastructure/services/apple-auth.types.ts +0 -0
  51. /package/src/{auth → domains/auth}/infrastructure/services/auth-guard.service.ts +0 -0
  52. /package/src/{auth → domains/auth}/infrastructure/services/crypto.util.ts +0 -0
  53. /package/src/{auth → domains/auth}/infrastructure/services/firestore-utils.service.ts +0 -0
  54. /package/src/{auth → domains/auth}/infrastructure/services/google-auth.types.ts +0 -0
  55. /package/src/{auth → domains/auth}/infrastructure/services/google-oauth.service.ts +0 -0
  56. /package/src/{auth → domains/auth}/infrastructure/services/user-document-builder.util.ts +0 -0
  57. /package/src/{auth → domains/auth}/infrastructure/services/user-document.service.ts +0 -0
  58. /package/src/{auth → domains/auth}/infrastructure/services/user-document.types.ts +0 -0
  59. /package/src/{auth → domains/auth}/infrastructure/stores/auth.store.ts +0 -0
  60. /package/src/{auth → domains/auth}/presentation/hooks/shared/auth-hooks.util.ts +0 -0
  61. /package/src/{auth → domains/auth}/presentation/hooks/shared/hook-utils.util.ts +0 -0
  62. /package/src/{auth → domains/auth}/presentation/hooks/shared/safe-state-hooks.util.ts +0 -0
  63. /package/src/{auth → domains/auth}/presentation/hooks/shared/state-hooks.util.ts +0 -0
  64. /package/src/{auth → domains/auth}/presentation/hooks/useAnonymousAuth.ts +0 -0
  65. /package/src/{auth → domains/auth}/presentation/hooks/useFirebaseAuth.ts +0 -0
  66. /package/src/{auth → domains/auth}/presentation/hooks/useGoogleOAuth.ts +0 -0
  67. /package/src/{auth → domains/auth}/presentation/hooks/useSocialAuth.ts +0 -0
  68. /package/src/{auth → domains/auth}/presentation/hooks/utils/auth-state-change.handler.ts +0 -0
  69. /package/src/{firestore → domains/firestore}/domain/constants/QuotaLimits.ts +0 -0
  70. /package/src/{firestore → domains/firestore}/domain/entities/QuotaMetrics.ts +0 -0
  71. /package/src/{firestore → domains/firestore}/domain/entities/RequestLog.ts +0 -0
  72. /package/src/{firestore → domains/firestore}/domain/services/QuotaCalculator.ts +0 -0
  73. /package/src/{firestore → domains/firestore}/index.ts +0 -0
  74. /package/src/{firestore → domains/firestore}/infrastructure/config/initializers/FirebaseFirestoreInitializer.ts +0 -0
  75. /package/src/{firestore → domains/firestore}/infrastructure/middleware/QueryDeduplicationMiddleware.ts +0 -0
  76. /package/src/{firestore → domains/firestore}/infrastructure/middleware/QuotaTrackingMiddleware.ts +0 -0
  77. /package/src/{firestore → domains/firestore}/infrastructure/repositories/BasePaginatedRepository.ts +0 -0
  78. /package/src/{firestore → domains/firestore}/infrastructure/repositories/BaseQueryRepository.ts +0 -0
  79. /package/src/{firestore → domains/firestore}/infrastructure/repositories/BaseRepository.ts +0 -0
  80. /package/src/{firestore → domains/firestore}/types/pagination.types.ts +0 -0
  81. /package/src/{firestore → domains/firestore}/utils/dateUtils.ts +0 -0
  82. /package/src/{firestore → domains/firestore}/utils/deduplication/pending-query-manager.util.ts +0 -0
  83. /package/src/{firestore → domains/firestore}/utils/deduplication/query-key-generator.util.ts +0 -0
  84. /package/src/{firestore → domains/firestore}/utils/deduplication/timer-manager.util.ts +0 -0
  85. /package/src/{firestore → domains/firestore}/utils/document-mapper.helper.ts +0 -0
  86. /package/src/{firestore → domains/firestore}/utils/firestore-helper.ts +0 -0
  87. /package/src/{firestore → domains/firestore}/utils/mapper/base-mapper.util.ts +0 -0
  88. /package/src/{firestore → domains/firestore}/utils/mapper/enrichment-mapper.util.ts +0 -0
  89. /package/src/{firestore → domains/firestore}/utils/mapper/multi-enrichment-mapper.util.ts +0 -0
  90. /package/src/{firestore → domains/firestore}/utils/operation/operation-executor.util.ts +0 -0
  91. /package/src/{firestore → domains/firestore}/utils/pagination.helper.ts +0 -0
  92. /package/src/{firestore → domains/firestore}/utils/query/filters.util.ts +0 -0
  93. /package/src/{firestore → domains/firestore}/utils/query/modifiers.util.ts +0 -0
  94. /package/src/{firestore → domains/firestore}/utils/query-builder.ts +0 -0
  95. /package/src/{firestore → domains/firestore}/utils/result/result.util.ts +0 -0
  96. /package/src/{domain → shared/domain}/errors/FirebaseError.ts +0 -0
  97. /package/src/{domain → shared/domain}/guards/firebase-error.guard.ts +0 -0
  98. /package/src/{domain → shared/domain}/utils/async-executor.util.ts +0 -0
  99. /package/src/{domain → shared/domain}/utils/error-handler.util.ts +0 -0
  100. /package/src/{domain → shared/domain}/utils/error-handlers/error-checkers.ts +0 -0
  101. /package/src/{domain → shared/domain}/utils/error-handlers/error-converters.ts +0 -0
  102. /package/src/{domain → shared/domain}/utils/error-handlers/error-messages.ts +0 -0
  103. /package/src/{domain → shared/domain}/utils/executors/advanced-executors.util.ts +0 -0
  104. /package/src/{domain → shared/domain}/utils/executors/basic-executors.util.ts +0 -0
  105. /package/src/{domain → shared/domain}/utils/executors/batch-executors.util.ts +0 -0
  106. /package/src/{domain → shared/domain}/utils/executors/error-converters.util.ts +0 -0
  107. /package/src/{domain → shared/domain}/utils/id-generator.util.ts +0 -0
  108. /package/src/{domain → shared/domain}/utils/index.ts +0 -0
  109. /package/src/{domain → shared/domain}/utils/result/result-creators.ts +0 -0
  110. /package/src/{domain → shared/domain}/utils/result/result-helpers.ts +0 -0
  111. /package/src/{domain → shared/domain}/utils/result/result-types.ts +0 -0
  112. /package/src/{domain → shared/domain}/utils/result.util.ts +0 -0
  113. /package/src/{domain → shared/domain}/utils/service-config.util.ts +0 -0
  114. /package/src/{domain → shared/domain}/utils/type-guards.util.ts +0 -0
  115. /package/src/{domain → shared/domain}/utils/validation.util.ts +0 -0
  116. /package/src/{domain → shared/domain}/utils/validators/composite.validator.ts +0 -0
  117. /package/src/{domain → shared/domain}/utils/validators/firebase.validator.ts +0 -0
  118. /package/src/{domain → shared/domain}/utils/validators/generic.validator.ts +0 -0
  119. /package/src/{domain → shared/domain}/utils/validators/string.validator.ts +0 -0
  120. /package/src/{domain → shared/domain}/utils/validators/url.validator.ts +0 -0
  121. /package/src/{domain → shared/domain}/utils/validators/user-input.validator.ts +0 -0
  122. /package/src/{domain → shared/domain}/value-objects/FirebaseConfig.ts +0 -0
  123. /package/src/{infrastructure → shared/infrastructure}/config/FirebaseClient.ts +0 -0
  124. /package/src/{infrastructure → shared/infrastructure}/config/FirebaseConfigLoader.ts +0 -0
  125. /package/src/{infrastructure → shared/infrastructure}/config/base/ClientStateManager.ts +0 -0
  126. /package/src/{infrastructure → shared/infrastructure}/config/base/ServiceClientSingleton.ts +0 -0
  127. /package/src/{infrastructure → shared/infrastructure}/config/initializers/FirebaseAppInitializer.ts +0 -0
  128. /package/src/{infrastructure → shared/infrastructure}/config/orchestrators/FirebaseInitializationOrchestrator.ts +0 -0
  129. /package/src/{infrastructure → shared/infrastructure}/config/services/FirebaseInitializationService.ts +0 -0
  130. /package/src/{infrastructure → shared/infrastructure}/config/services/FirebaseServiceInitializer.ts +0 -0
  131. /package/src/{infrastructure → shared/infrastructure}/config/state/FirebaseClientState.ts +0 -0
  132. /package/src/{infrastructure → shared/infrastructure}/config/validators/FirebaseConfigValidator.ts +0 -0
@@ -1,239 +0,0 @@
1
- # Auth Configuration
2
-
3
- Firebase Authentication client initialization, configuration management, and service access.
4
-
5
- ## Purpose
6
-
7
- Provides core Firebase Auth client functionality including initialization, state management, service access, error handling, and client reset.
8
-
9
- ## For AI Agents
10
-
11
- ### Before Using Auth Config
12
-
13
- 1. **INITIALIZE** Auth once at app startup
14
- 2. **CHECK** initialization status before use
15
- 3. **USE** getFirebaseAuth() to get Auth instance
16
- 4. **HANDLE** initialization errors appropriately
17
- 5. **NEVER** initialize Auth multiple times
18
-
19
- ### Required Practices
20
-
21
- 1. **Initialize once** - Call initializeFirebaseAuth() at app startup
22
- 2. **Check status** - Verify initialization before using Auth
23
- 3. **Get Auth instance** - Use getFirebaseAuth() after initialization
24
- 4. **Handle errors** - Check for initialization errors
25
- 5. **Use services** - Use auth services instead of direct Auth SDK
26
-
27
- ### Forbidden Practices
28
-
29
- ## ❌ NEVER
30
-
31
- - Initialize Firebase Auth multiple times
32
- - Use Auth SDK before initialization
33
- - Use getAuth() from firebase/auth directly
34
- - Ignore initialization errors
35
- - Skip initialization status check
36
-
37
- ## ⚠️ Avoid
38
-
39
- - Initializing Auth in components
40
- - Not checking initialization status
41
- - Direct Firebase Auth SDK usage
42
- - Initializing without Firebase app
43
- - Not handling initialization failures
44
-
45
- ## Initialization Strategy
46
-
47
- ### Basic Initialization
48
-
49
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/config`
50
-
51
- **Function:** `initializeFirebaseAuth()`
52
-
53
- **Returns:** `Promise<void>`
54
-
55
- **When to Use:**
56
- - App startup (after Firebase initialized)
57
- - Before any auth operations
58
- - Root component initialization
59
-
60
- **Initialization Flow:**
61
- 1. Verify Firebase app initialized
62
- 2. Get Firebase app instance
63
- 3. Initialize Auth with app
64
- 4. Set initialization state
65
- 5. Handle errors appropriately
66
-
67
- ### Check Initialization Status
68
-
69
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/config`
70
-
71
- **Functions:**
72
- - `isFirebaseAuthInitialized()` - Check if Auth initialized
73
- - `isFirebaseAuthInitializing()` - Check if initializing
74
- - `getFirebaseAuthInitializationError()` - Get error if failed
75
-
76
- **Returns:**
77
- - `boolean` for status checks
78
- - `Error | null` for error check
79
-
80
- **When to Use:**
81
- - Before auth operations
82
- - Before using auth services
83
- - Error recovery
84
- - Status display
85
-
86
- **Usage Strategy:**
87
- 1. Check isFirebaseAuthInitialized()
88
- 2. If false, show loading or initialize
89
- 3. If error, show error message
90
- 4. Proceed with auth operations
91
-
92
- ## Service Access
93
-
94
- ### Get Auth Instance
95
-
96
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/config`
97
-
98
- **Function:** `getFirebaseAuth()`
99
-
100
- **Returns:** `Auth` instance from Firebase Auth SDK
101
-
102
- **Usage Strategy:**
103
- 1. Check initialization status first
104
- 2. Call getFirebaseAuth()
105
- 3. Use Auth instance for operations
106
- 4. Handle errors appropriately
107
-
108
- **When to Use:**
109
- - Custom auth operations
110
- - Direct Auth SDK usage (rare)
111
- - Advanced auth features
112
- - Auth service implementations
113
-
114
- **Important:** Prefer using auth services over direct Auth SDK usage
115
-
116
- ### Reset Client
117
-
118
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/config`
119
-
120
- **Function:** `resetFirebaseAuthClient()`
121
-
122
- **Purpose:** Reset Auth client state (useful for testing)
123
-
124
- **When to Use:**
125
- - Testing scenarios
126
- - Error recovery
127
- - Reinitialization
128
- - Development
129
-
130
- **Usage Strategy:**
131
- 1. Call resetFirebaseAuthClient()
132
- 2. Reinitialize if needed
133
- 3. Use only in development/testing
134
- 4. Never use in production
135
-
136
- ## Common Mistakes to Avoid
137
-
138
- 1. ❌ Initializing Auth multiple times
139
- - ✅ Initialize once at app startup
140
-
141
- 2. ❌ Not checking initialization status
142
- - ✅ Always check isFirebaseAuthInitialized()
143
-
144
- 3. ❌ Using getAuth() from firebase/auth
145
- - ✅ Use getFirebaseAuth() from auth config
146
-
147
- 4. ❌ Initializing before Firebase app
148
- - ✅ Initialize Firebase first, then Auth
149
-
150
- 5. ❌ Ignoring initialization errors
151
- - ✅ Handle and display errors
152
-
153
- ## AI Agent Instructions
154
-
155
- ### When Initializing Auth
156
-
157
- 1. Initialize Firebase first
158
- 2. Call initializeFirebaseAuth()
159
- 3. Await initialization completion
160
- 4. Check for errors
161
- 5. Show error message if failed
162
-
163
- ### When Using Auth Services
164
-
165
- 1. Check Auth initialization status
166
- 2. If not initialized, initialize first
167
- 3. Use auth services (not direct SDK)
168
- 4. Handle errors appropriately
169
- 5. Show user feedback
170
-
171
- ### When Getting Auth Instance
172
-
173
- 1. Check isFirebaseAuthInitialized()
174
- 2. Call getFirebaseAuth()
175
- 3. Use Auth instance
176
- 4. Handle uninitialized state
177
- 5. Prefer auth services over direct usage
178
-
179
- ## Code Quality Standards
180
-
181
- ### Initialization
182
-
183
- - Initialize once at startup
184
- - Check status before use
185
- - Handle errors gracefully
186
- - Show loading states
187
- - Provide error feedback
188
-
189
- ### Error Handling
190
-
191
- - Catch initialization errors
192
- - Store error in state
193
- - Provide error context
194
- - Allow retry/recovery
195
- - Log for debugging
196
-
197
- ## Performance Considerations
198
-
199
- ### Initialization Overhead
200
-
201
- - One-time cost at app startup
202
- - Async initialization (non-blocking)
203
- - ~50-200ms typical
204
- - Initialize once, reuse Auth instance
205
- - Don't reinitialize unnecessarily
206
-
207
- ### State Checking
208
-
209
- - Fast boolean checks
210
- - No performance overhead
211
- - Safe to call frequently
212
- - Use before auth operations
213
- - Prevents errors
214
-
215
- ## Related Documentation
216
-
217
- - [Auth Module README](../../README.md)
218
- - [Auth Services README](../services/README.md)
219
- - [Firebase Infrastructure Config README](../../../infrastructure/config/README.md)
220
-
221
- ## API Reference
222
-
223
- ### Main Functions
224
-
225
- **Import Path:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/config`
226
-
227
- | Function | Returns | Description |
228
- |----------|---------|-------------|
229
- | `initializeFirebaseAuth` | `Promise<void>` | Initialize Firebase Auth |
230
- | `getFirebaseAuth` | `Auth` | Get Auth instance |
231
- | `isFirebaseAuthInitialized` | `boolean` | Check if initialized |
232
- | `isFirebaseAuthInitializing` | `boolean` | Check if initializing |
233
- | `getFirebaseAuthInitializationError` | `Error \| null` | Get initialization error |
234
- | `resetFirebaseAuthClient` | `void` | Reset client state (testing) |
235
-
236
- ---
237
-
238
- **Last Updated:** 2025-01-08
239
- **Maintainer:** Auth Module Team
@@ -1,346 +0,0 @@
1
- # Auth Services
2
-
3
- Firebase Authentication service layer providing authentication operations, utilities, and guards.
4
-
5
- ## Purpose
6
-
7
- Provides service layer for Firebase Authentication including anonymous auth, Google OAuth, Apple Auth, reauthentication, account deletion, auth guards, and auth-related Firestore utilities.
8
-
9
- ## For AI Agents
10
-
11
- ### Before Using Auth Services
12
-
13
- 1. **USE** services (never Firebase Auth SDK directly in UI)
14
- 2. **HANDLE** service results properly
15
- 3. **CHECK** success property before using data
16
- 4. **HANDLE** errors appropriately
17
- 5. **USE** auth guards for protected routes
18
-
19
- ### Required Practices
20
-
21
- 1. **Use services** - Import from auth infrastructure/services
22
- 2. **Check results** - Always check success property
23
- 3. **Handle errors** - Display user-friendly messages
24
- 4. **Use guards** - Protect routes with authGuardService
25
- 5. **Clean up** - Delete Firestore data on account deletion
26
-
27
- ### Forbidden Practices
28
-
29
- ## ❌ NEVER
30
-
31
- - Use Firebase Auth SDK directly in UI components
32
- - Ignore success property in results
33
- - Skip error handling
34
- - Mix service concerns
35
- - Delete Auth without Firestore cleanup
36
-
37
- ## ⚠️ Avoid
38
-
39
- - Not checking success before using user data
40
- - Showing technical error messages
41
- - Not using auth guards for protected routes
42
- - Forgetting to delete Firestore data
43
- - Hardcoding auth configuration
44
-
45
- ## Service Overview
46
-
47
- ### AnonymousAuthService
48
-
49
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
50
-
51
- **Purpose:** Handle anonymous (guest) user authentication
52
-
53
- **Methods:**
54
- - `signIn()` - Sign in as anonymous user
55
-
56
- **Returns:** `Promise<AnonymousAuthResult>`
57
- - `success: boolean` - Operation succeeded
58
- - `user?: User` - Authenticated user
59
- - `error?: Error` - Error if failed
60
-
61
- **Usage Strategy:**
62
- 1. Call signIn() for guest access
63
- 2. Check success property
64
- 3. Access user data if successful
65
- 4. Handle errors appropriately
66
- 5. Prompt to upgrade to permanent account
67
-
68
- **When to Use:**
69
- - Quick app tryout without registration
70
- - Temporary user sessions
71
- - Testing without credentials
72
- - Guest access with limited functionality
73
-
74
- ### GoogleAuthService
75
-
76
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
77
-
78
- **Purpose:** Handle Google OAuth authentication
79
-
80
- **Methods:**
81
- - `signIn(config)` - Sign in with Google
82
-
83
- **Parameters:**
84
- - `config: GoogleAuthConfig`
85
- - `clientId: string` - Google OAuth Client ID
86
-
87
- **Returns:** `Promise<GoogleAuthResult>`
88
- - `success: boolean` - Operation succeeded
89
- - `user?: User` - Authenticated user
90
- - `idToken?: string` - Google ID token
91
- - `error?: Error` - Error if failed
92
-
93
- **Usage Strategy:**
94
- 1. Configure with Google Client ID
95
- 2. Call signIn() on user action
96
- 3. Check success property
97
- 4. Access user and idToken if successful
98
- 5. Handle errors gracefully
99
-
100
- **When to Use:**
101
- - Primary authentication method
102
- - Google account sign-in
103
- - Account linking
104
- - Reauthentication
105
-
106
- ### AppleAuthService
107
-
108
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
109
-
110
- **Purpose:** Handle Apple ID authentication (iOS only)
111
-
112
- **Methods:**
113
- - `signIn()` - Sign in with Apple ID
114
-
115
- **Returns:** `Promise<AppleAuthResult>`
116
- - `success: boolean` - Operation succeeded
117
- - `user?: User` - Authenticated user
118
- - `authorizationCode?: string` - Apple authorization code
119
- - `error?: Error` - Error if failed
120
-
121
- **Usage Strategy:**
122
- 1. Call signIn() on user action (iOS only)
123
- 2. Automatically skipped on Android
124
- 3. Check success property
125
- 4. Access user data if successful
126
- 5. Handle errors appropriately
127
-
128
- **When to Use:**
129
- - iOS applications
130
- - Alternative to Google sign-in
131
- - Privacy-focused authentication
132
- - Account linking
133
-
134
- ## Account Operations
135
-
136
- ### ReauthenticationService
137
-
138
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
139
-
140
- **Purpose:** Handle user reauthentication for sensitive operations
141
-
142
- **Methods:**
143
- - `reauthenticate(user)` - Reauthenticate current user
144
-
145
- **When to Use:**
146
- - Before account deletion
147
- - Before password change
148
- - Before sensitive operations
149
- - Email verification
150
-
151
- **Strategy:**
152
- 1. Verify user identity
153
- 2. Call reauthenticate method
154
- 3. Handle reauthentication
155
- 4. Proceed with sensitive operation
156
- 5. Handle errors appropriately
157
-
158
- ### Account Deletion Service
159
-
160
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
161
-
162
- **Purpose:** Handle complete account deletion including Auth and Firestore data
163
-
164
- **Methods:**
165
- - `deleteCurrentUser()` - Delete current user account
166
-
167
- **Cleanup Process:**
168
- 1. Delete Firebase Auth account
169
- 2. Automatically delete Firestore user data
170
- 3. Clean up Storage files (manual if needed)
171
- 4. Sign out user
172
- 5. Navigate to login screen
173
-
174
- **When to Use:**
175
- - User requests account deletion
176
- - GDPR compliance
177
- - User data cleanup
178
- - Account testing
179
-
180
- **Strategy:**
181
- 1. Confirm deletion with user
182
- 2. Call deleteCurrentUser()
183
- 3. Auth deletion automatic
184
- 4. Firestore cleanup automatic
185
- 5. Manual Storage cleanup if needed
186
-
187
- ## Route Protection
188
-
189
- ### AuthGuardService
190
-
191
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
192
-
193
- **Purpose:** Protect routes that require authentication
194
-
195
- **Methods:**
196
- - `canActivate()` - Check if route can be activated
197
- - `canActivateAnonymous()` - Check if anonymous users allowed
198
-
199
- **Returns:** `boolean` - Whether route can be accessed
200
-
201
- **Usage Strategy:**
202
- 1. Use in protected route components
203
- 2. Check canActivate() before rendering
204
- 3. Redirect to login if not authenticated
205
- 4. Handle anonymous users appropriately
206
- 5. Show loading state during check
207
-
208
- **When to Use:**
209
- - Pages requiring authentication
210
- - User profile pages
211
- - Dashboard and settings
212
- - Protected features
213
-
214
- ## Firestore Utilities
215
-
216
- ### AuthFirestoreUtils
217
-
218
- **Import From:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
219
-
220
- **Purpose:** Helper functions for auth-related Firestore operations
221
-
222
- **Utilities:**
223
- - User document path resolution
224
- - User data creation/update
225
- - User data cleanup on deletion
226
- - Auth state synchronization
227
-
228
- **When to Use:**
229
- - Creating user documents in Firestore
230
- - Updating user profile data
231
- - Cleaning up user data
232
- - Syncing auth state with database
233
-
234
- ## Service Result Types
235
-
236
- ### AuthResult Pattern
237
-
238
- **Import From:** All auth services return similar result types
239
-
240
- **Common Properties:**
241
- - `success: boolean` - Operation succeeded
242
- - `user?: User` - Authenticated user (when applicable)
243
- - `error?: Error` - Error if operation failed
244
-
245
- **Usage:**
246
- 1. Call service method
247
- 2. Check result.success
248
- 3. Use result.user if success
249
- 4. Handle result.error if failed
250
- 5. Never assume success
251
-
252
- ## Common Mistakes to Avoid
253
-
254
- 1. ❌ Not checking success property
255
- - ✅ Always check result.success first
256
-
257
- 2. ❌ Using Firebase Auth SDK directly
258
- - ✅ Use auth services
259
-
260
- 3. ❌ Not handling errors
261
- - ✅ Check result.error and display message
262
-
263
- 4. ❌ Deleting Auth without Firestore cleanup
264
- - ✅ Use deleteCurrentUser() for complete cleanup
265
-
266
- 5. ❌ Not protecting routes
267
- - ✅ Use authGuardService
268
-
269
- ## AI Agent Instructions
270
-
271
- ### When Using Auth Services
272
-
273
- 1. Import service from auth infrastructure/services
274
- 2. Call service method with appropriate parameters
275
- 3. Check result.success property
276
- 4. Use result.user data if successful
277
- 5. Handle result.error appropriately
278
-
279
- ### When Protecting Route
280
-
281
- 1. Use authGuardService.canActivate()
282
- 2. Check result before showing protected content
283
- 3. Redirect to login if not authenticated
284
- 4. Handle anonymous users appropriately
285
- 5. Show loading state during check
286
-
287
- ### When Deleting Account
288
-
289
- 1. Confirm deletion with user
290
- 2. Call deleteCurrentUser() service
291
- 3. Firestore cleanup automatic
292
- 4. Clean up Storage files if needed
293
- 5. Sign out and navigate to login
294
-
295
- ## Code Quality Standards
296
-
297
- ### TypeScript
298
-
299
- - Type all service methods
300
- - Use proper result types
301
- - Handle errors with types
302
- - Export service instances
303
- - Document service behavior
304
-
305
- ### Error Handling
306
-
307
- - Always return success property
308
- - Include error details
309
- - Provide context in errors
310
- - Handle edge cases
311
- - Test error flows
312
-
313
- ## Related Documentation
314
-
315
- - [Auth Module README](../../README.md)
316
- - [Auth Stores README](../stores/README.md)
317
- - [Auth Hooks README](../../presentation/hooks/README.md)
318
- - [Auth Errors README](../../domain/errors/README.md)
319
-
320
- ## API Reference
321
-
322
- ### Main Services
323
-
324
- **Import Path:** `@umituz/react-native-firebase/auth` or `src/auth/infrastructure/services`
325
-
326
- | Service | Purpose | Methods |
327
- |---------|---------|---------|
328
- | `anonymousAuthService` | Anonymous authentication | `signIn()` |
329
- | `googleAuthService` | Google OAuth | `signIn(config)` |
330
- | `appleAuthService` | Apple ID authentication | `signIn()` |
331
- | `authGuardService` | Route protection | `canActivate()`, `canActivateAnonymous()` |
332
- | `reauthenticationService` | User reauthentication | `reauthenticate(user)` |
333
- | `accountDeletionService` | Account deletion | `deleteCurrentUser()` |
334
-
335
- ### Result Types
336
-
337
- | Type | Properties |
338
- |------|------------|
339
- | `AnonymousAuthResult` | success, user?, error? |
340
- | `GoogleAuthResult` | success, user?, idToken?, error? |
341
- | `AppleAuthResult` | success, user?, authorizationCode?, error? |
342
-
343
- ---
344
-
345
- **Last Updated:** 2025-01-08
346
- **Maintainer:** Auth Module Team