@umituz/react-native-firebase 1.13.57 → 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,339 @@
|
|
|
1
|
+
# Auth Module
|
|
2
|
+
|
|
3
|
+
Firebase Authentication module providing comprehensive authentication services and state management.
|
|
4
|
+
|
|
5
|
+
## 🎯 Purpose
|
|
6
|
+
|
|
7
|
+
Provides authentication functionality using Firebase Auth JS SDK with a clean, maintainable architecture following Domain-Driven Design principles.
|
|
8
|
+
|
|
9
|
+
## 📋 For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Modifying This Module
|
|
12
|
+
|
|
13
|
+
1. **READ** this entire README
|
|
14
|
+
2. **UNDERSTAND** the architecture (domain → infrastructure → presentation)
|
|
15
|
+
3. **FOLLOW** existing patterns - don't reinvent
|
|
16
|
+
4. **CHECK** file size limits (max 200 lines per file)
|
|
17
|
+
5. **RESPECT** layer boundaries
|
|
18
|
+
|
|
19
|
+
### Layer Rules
|
|
20
|
+
|
|
21
|
+
**Domain Layer (`domain/`)**
|
|
22
|
+
- Contains business logic, entities, and errors
|
|
23
|
+
- No external dependencies (Firebase-free)
|
|
24
|
+
- Defines interfaces and value objects
|
|
25
|
+
|
|
26
|
+
**Infrastructure Layer (`infrastructure/`)**
|
|
27
|
+
- Contains Firebase integration and services
|
|
28
|
+
- Depends on Firebase SDK
|
|
29
|
+
- Implements interfaces defined in domain
|
|
30
|
+
|
|
31
|
+
**Presentation Layer (`presentation/`)**
|
|
32
|
+
- Contains React hooks and UI utilities
|
|
33
|
+
- Depends on infrastructure layer
|
|
34
|
+
- No business logic
|
|
35
|
+
|
|
36
|
+
## 🏗️ Architecture
|
|
37
|
+
|
|
38
|
+
**Directory Structure:**
|
|
39
|
+
|
|
40
|
+
**domain/** - Business logic (Firebase-free)
|
|
41
|
+
- entities/ - Domain entities (AnonymousUser)
|
|
42
|
+
- value-objects/ - Value objects (FirebaseAuthConfig)
|
|
43
|
+
- errors/ - Domain errors (FirebaseAuthError)
|
|
44
|
+
|
|
45
|
+
**infrastructure/** - Implementation (Firebase-dependent)
|
|
46
|
+
- config/ - Firebase Auth initialization
|
|
47
|
+
- services/ - Auth services (Google, Apple, Anonymous)
|
|
48
|
+
- stores/ - State management (Zustand)
|
|
49
|
+
|
|
50
|
+
**presentation/** - UI integration
|
|
51
|
+
- hooks/ - React hooks
|
|
52
|
+
|
|
53
|
+
## ✅ Required Practices
|
|
54
|
+
|
|
55
|
+
### Authentication Flow
|
|
56
|
+
|
|
57
|
+
1. **Always use hooks** for auth state in UI components
|
|
58
|
+
2. **Initialize Firebase once** at app startup (in infrastructure layer)
|
|
59
|
+
3. **Use services** for auth operations (not Firebase SDK directly)
|
|
60
|
+
4. **Protect routes** with auth guards
|
|
61
|
+
5. **Handle auth errors** with user-friendly messages
|
|
62
|
+
|
|
63
|
+
### State Management
|
|
64
|
+
|
|
65
|
+
1. Use Zustand stores for auth state
|
|
66
|
+
2. Persist only essential data (user ID, auth status)
|
|
67
|
+
3. Don't persist transient states (loading, errors)
|
|
68
|
+
4. Clear state on logout
|
|
69
|
+
|
|
70
|
+
### Error Handling
|
|
71
|
+
|
|
72
|
+
1. Use domain-specific error classes
|
|
73
|
+
2. Never throw primitive values (always Error instances)
|
|
74
|
+
3. Include error codes for programmatic handling
|
|
75
|
+
4. Log errors appropriately
|
|
76
|
+
|
|
77
|
+
## 🚫 Forbidden Practices
|
|
78
|
+
|
|
79
|
+
### ❌ NEVER
|
|
80
|
+
|
|
81
|
+
- Use Firebase Auth SDK directly in UI components
|
|
82
|
+
- Bypass auth services to access Firebase
|
|
83
|
+
- Mix architectural layers (e.g., import Firebase in domain layer)
|
|
84
|
+
- Create circular dependencies
|
|
85
|
+
- Put authentication logic in UI components
|
|
86
|
+
- Hardcode credentials or API keys
|
|
87
|
+
- Ignore authentication errors
|
|
88
|
+
|
|
89
|
+
### ⚠️ Avoid
|
|
90
|
+
|
|
91
|
+
- Multiple Firebase initializations
|
|
92
|
+
- Not cleaning up auth listeners
|
|
93
|
+
- Storing sensitive data in plain text
|
|
94
|
+
- Ignoring auth state changes
|
|
95
|
+
|
|
96
|
+
## 🎯 Usage Strategies
|
|
97
|
+
|
|
98
|
+
### For Authentication in UI
|
|
99
|
+
|
|
100
|
+
**Strategy:** Use React hooks for all auth operations in UI components.
|
|
101
|
+
|
|
102
|
+
1. Use `useFirebaseAuth` for general auth state
|
|
103
|
+
2. Use `useAnonymousAuth` for anonymous authentication
|
|
104
|
+
3. Use `useSocialAuth` for Google/Apple authentication
|
|
105
|
+
4. Never import Firebase Auth SDK directly in UI
|
|
106
|
+
|
|
107
|
+
**Correct Pattern:**
|
|
108
|
+
- ✅ Use `useFirebaseAuth()` hook for auth state
|
|
109
|
+
- ❌ Never import `getAuth` from firebase/auth directly in UI
|
|
110
|
+
|
|
111
|
+
### For Protected Routes
|
|
112
|
+
|
|
113
|
+
**Strategy:** Use auth guards to protect routes that require authentication.
|
|
114
|
+
|
|
115
|
+
1. Use `authGuardService.canActivate()` to check auth status
|
|
116
|
+
2. Redirect unauthenticated users to login
|
|
117
|
+
3. Handle anonymous users appropriately (allow or deny access)
|
|
118
|
+
|
|
119
|
+
### For Account Operations
|
|
120
|
+
|
|
121
|
+
**Strategy:** Use dedicated services for account operations.
|
|
122
|
+
|
|
123
|
+
1. Use `deleteCurrentUser()` for account deletion (includes Firestore cleanup)
|
|
124
|
+
2. Use reauthentication services before sensitive operations
|
|
125
|
+
3. Handle errors appropriately
|
|
126
|
+
|
|
127
|
+
### For Anonymous Users
|
|
128
|
+
|
|
129
|
+
**Strategy:** Treat anonymous users as temporary accounts.
|
|
130
|
+
|
|
131
|
+
1. Allow basic functionality for anonymous users
|
|
132
|
+
2. Prompt to upgrade to permanent account
|
|
133
|
+
3. Track anonymous user session duration
|
|
134
|
+
4. Migrate anonymous account to permanent account when upgrading
|
|
135
|
+
|
|
136
|
+
## 🔧 Service Usage
|
|
137
|
+
|
|
138
|
+
### Anonymous Authentication
|
|
139
|
+
|
|
140
|
+
**Service:** `anonymousAuthService` in `infrastructure/services/`
|
|
141
|
+
|
|
142
|
+
**Usage Strategy:**
|
|
143
|
+
- Use for quick onboarding without registration
|
|
144
|
+
- Limit functionality for anonymous users
|
|
145
|
+
- Prompt users to create permanent account
|
|
146
|
+
- Use for temporary data storage
|
|
147
|
+
|
|
148
|
+
**When to Use:**
|
|
149
|
+
- User wants to try the app before signing up
|
|
150
|
+
- Temporary session needed
|
|
151
|
+
- Testing and demos
|
|
152
|
+
|
|
153
|
+
### Google Authentication
|
|
154
|
+
|
|
155
|
+
**Service:** `googleAuthService` in `infrastructure/services/`
|
|
156
|
+
|
|
157
|
+
**Usage Strategy:**
|
|
158
|
+
- Use for Google OAuth sign-in
|
|
159
|
+
- Requires Google Client ID configuration
|
|
160
|
+
- Handle sign-in errors gracefully
|
|
161
|
+
|
|
162
|
+
**When to Use:**
|
|
163
|
+
- Primary authentication method
|
|
164
|
+
- Account linking
|
|
165
|
+
- Reauthentication
|
|
166
|
+
|
|
167
|
+
### Apple Authentication
|
|
168
|
+
|
|
169
|
+
**Service:** `appleAuthService` in `infrastructure/services/`
|
|
170
|
+
|
|
171
|
+
**Usage Strategy:**
|
|
172
|
+
- Use for Apple ID sign-in on iOS
|
|
173
|
+
- Automatically skip on Android
|
|
174
|
+
- Handle sign-in errors gracefully
|
|
175
|
+
|
|
176
|
+
**When to Use:**
|
|
177
|
+
- iOS applications
|
|
178
|
+
- Alternative to Google sign-in
|
|
179
|
+
|
|
180
|
+
## 🤖 AI Agent Instructions
|
|
181
|
+
|
|
182
|
+
### When Adding New Auth Provider
|
|
183
|
+
|
|
184
|
+
1. Create service in `infrastructure/services/`
|
|
185
|
+
2. Follow existing service patterns
|
|
186
|
+
3. Return consistent result type: `{ success: boolean; user?: User; error?: Error }`
|
|
187
|
+
4. Add error handling
|
|
188
|
+
5. Update this README
|
|
189
|
+
|
|
190
|
+
### When Creating New Hook
|
|
191
|
+
|
|
192
|
+
1. Place in `presentation/hooks/`
|
|
193
|
+
2. Follow existing hook patterns
|
|
194
|
+
3. Return consistent interface: `{ user, isLoading, isAuthenticated, error }`
|
|
195
|
+
4. Handle loading and error states
|
|
196
|
+
5. Update this README
|
|
197
|
+
|
|
198
|
+
### When Modifying State Management
|
|
199
|
+
|
|
200
|
+
1. Keep state minimal (only essential data)
|
|
201
|
+
2. Use Zustand persist middleware
|
|
202
|
+
3. Don't persist transient states
|
|
203
|
+
4. Clear state properly on logout
|
|
204
|
+
5. Update this README
|
|
205
|
+
|
|
206
|
+
### File Organization Rules
|
|
207
|
+
|
|
208
|
+
1. Keep files under 200 lines
|
|
209
|
+
2. One service per file
|
|
210
|
+
3. One hook per file
|
|
211
|
+
4. Group related functionality
|
|
212
|
+
5. Extract reusable logic into utilities
|
|
213
|
+
|
|
214
|
+
## 📏 Code Quality Standards
|
|
215
|
+
|
|
216
|
+
### File Size
|
|
217
|
+
|
|
218
|
+
- **Maximum:** 200 lines per file
|
|
219
|
+
- **Strategy:** Split large files into smaller modules
|
|
220
|
+
- **Example:** If auth service is 300 lines, split into `auth-base.service.ts` and `auth-social.service.ts`
|
|
221
|
+
|
|
222
|
+
### TypeScript
|
|
223
|
+
|
|
224
|
+
- Use strict mode
|
|
225
|
+
- Define proper types for all functions
|
|
226
|
+
- Export types used by other modules
|
|
227
|
+
- Never use `any` type
|
|
228
|
+
|
|
229
|
+
### Naming Conventions
|
|
230
|
+
|
|
231
|
+
- Files: `kebab-case.ts` (e.g., `google-auth.service.ts`)
|
|
232
|
+
- Classes: `PascalCase` (e.g., `GoogleAuthService`)
|
|
233
|
+
- Functions/Variables: `camelCase` (e.g., `signInUser`)
|
|
234
|
+
- Constants: `UPPER_SNAKE_CASE` (e.g., `MAX_RETRIES`)
|
|
235
|
+
- Interfaces/Types: `PascalCase` (e.g., `AuthResult`)
|
|
236
|
+
|
|
237
|
+
### Error Handling
|
|
238
|
+
|
|
239
|
+
1. Use `FirebaseAuthError` for auth errors
|
|
240
|
+
2. Include error codes
|
|
241
|
+
3. Provide context in error messages
|
|
242
|
+
4. Never throw primitives
|
|
243
|
+
|
|
244
|
+
## 📚 Related Documentation
|
|
245
|
+
|
|
246
|
+
- [Development Guidelines](../../CONTRIBUTING.md)
|
|
247
|
+
- [Auth Hooks](./presentation/hooks/README.md)
|
|
248
|
+
- [Auth Services](./infrastructure/services/README.md)
|
|
249
|
+
- [Auth Domain](./domain/README.md)
|
|
250
|
+
- [Auth Configuration](./infrastructure/config/README.md)
|
|
251
|
+
|
|
252
|
+
## 🔗 API Reference
|
|
253
|
+
|
|
254
|
+
### Main Exports
|
|
255
|
+
|
|
256
|
+
**Hooks:**
|
|
257
|
+
- `useFirebaseAuth()` - General auth state management
|
|
258
|
+
- `useAnonymousAuth()` - Anonymous authentication
|
|
259
|
+
- `useSocialAuth(config)` - Social auth (Google, Apple)
|
|
260
|
+
|
|
261
|
+
**Services:**
|
|
262
|
+
- `anonymousAuthService` - Anonymous auth operations
|
|
263
|
+
- `googleAuthService` - Google OAuth
|
|
264
|
+
- `appleAuthService` - Apple ID auth
|
|
265
|
+
- `authGuardService` - Route protection
|
|
266
|
+
|
|
267
|
+
**Utilities:**
|
|
268
|
+
- `checkAuthState()` - Comprehensive auth check
|
|
269
|
+
- `getCurrentUserId()` - Get current user ID
|
|
270
|
+
- `deleteCurrentUser()` - Delete current account
|
|
271
|
+
- And more...
|
|
272
|
+
|
|
273
|
+
**See:** [Auth Module Index](./index.ts) for complete export list
|
|
274
|
+
|
|
275
|
+
## 🎓 Key Concepts
|
|
276
|
+
|
|
277
|
+
### Domain-Driven Design in Auth
|
|
278
|
+
|
|
279
|
+
**Why DDD?**
|
|
280
|
+
- Separates business logic from Firebase SDK
|
|
281
|
+
- Makes code testable without Firebase
|
|
282
|
+
- Allows easy switching of auth providers
|
|
283
|
+
- Clean architecture
|
|
284
|
+
|
|
285
|
+
**How it works:**
|
|
286
|
+
1. **Domain layer** defines what auth operations exist
|
|
287
|
+
2. **Infrastructure layer** implements them with Firebase
|
|
288
|
+
3. **Presentation layer** exposes them to React Native
|
|
289
|
+
|
|
290
|
+
### Repository Pattern
|
|
291
|
+
|
|
292
|
+
**Note:** Auth doesn't use repository pattern (that's for Firestore). Auth uses **Service Pattern** instead.
|
|
293
|
+
|
|
294
|
+
### State Management
|
|
295
|
+
|
|
296
|
+
**Why Zustand?**
|
|
297
|
+
- Simple and lightweight
|
|
298
|
+
- Built-in persist middleware
|
|
299
|
+
- Easy to test
|
|
300
|
+
- No boilerplate
|
|
301
|
+
|
|
302
|
+
## 🚨 Common Mistakes to Avoid
|
|
303
|
+
|
|
304
|
+
1. ❌ Using Firebase Auth SDK directly in components
|
|
305
|
+
- ✅ Use hooks instead
|
|
306
|
+
|
|
307
|
+
2. ❌ Not cleaning up auth listeners
|
|
308
|
+
- ✅ Always cleanup on unmount
|
|
309
|
+
|
|
310
|
+
3. ❌ Hardcoding auth configuration
|
|
311
|
+
- ✅ Use environment variables
|
|
312
|
+
|
|
313
|
+
4. ❌ Ignoring auth errors
|
|
314
|
+
- ✅ Handle errors appropriately
|
|
315
|
+
|
|
316
|
+
5. ❌ Creating circular dependencies
|
|
317
|
+
- ✅ Respect layer boundaries
|
|
318
|
+
|
|
319
|
+
## 📝 Module Maintenance
|
|
320
|
+
|
|
321
|
+
### When Code Changes
|
|
322
|
+
|
|
323
|
+
1. Update this README if behavior changes
|
|
324
|
+
2. Add new forbidden practices as needed
|
|
325
|
+
3. Update AI instructions for new patterns
|
|
326
|
+
4. Keep documentation in sync
|
|
327
|
+
|
|
328
|
+
### When Adding New Features
|
|
329
|
+
|
|
330
|
+
1. Consider architectural impact
|
|
331
|
+
2. Place in correct layer
|
|
332
|
+
3. Follow existing patterns
|
|
333
|
+
4. Add error handling
|
|
334
|
+
5. Update documentation
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
**Last Updated:** 2025-01-08
|
|
339
|
+
**Maintainer:** Auth Module Team
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# Auth Domain
|
|
2
|
+
|
|
3
|
+
Domain layer for Firebase Authentication containing business logic, entities, value objects, and domain errors.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Implements Domain-Driven Design (DDD) principles for Authentication, separating business logic from infrastructure concerns and providing a clean architecture.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Auth Domain
|
|
12
|
+
|
|
13
|
+
1. **UNDERSTAND** DDD architecture (domain → infrastructure → presentation)
|
|
14
|
+
2. **USE** domain entities (not infrastructure)
|
|
15
|
+
3. **NEVER** import Firebase SDK in domain layer
|
|
16
|
+
4. **DEFINE** business rules in domain
|
|
17
|
+
5. **KEEP** domain layer Firebase-free
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Keep domain Firebase-free** - No Firebase imports
|
|
22
|
+
2. **Define entities** - Business entities with behavior
|
|
23
|
+
3. **Create value objects** - Immutable configuration types
|
|
24
|
+
4. **Define domain errors** - Custom error classes
|
|
25
|
+
5. **Write business logic** - In domain, not infrastructure
|
|
26
|
+
|
|
27
|
+
### Forbidden Practices
|
|
28
|
+
|
|
29
|
+
## ❌ NEVER
|
|
30
|
+
|
|
31
|
+
- Import Firebase Auth SDK in domain layer
|
|
32
|
+
- Mix infrastructure concerns in domain
|
|
33
|
+
- Create anemic domain models
|
|
34
|
+
- Skip domain validation
|
|
35
|
+
- Put business logic in infrastructure
|
|
36
|
+
|
|
37
|
+
## ⚠️ Avoid
|
|
38
|
+
|
|
39
|
+
- Leaking domain logic to infrastructure
|
|
40
|
+
- Not validating business rules
|
|
41
|
+
- Missing domain entities
|
|
42
|
+
- Complex domain services
|
|
43
|
+
- Unclear domain boundaries
|
|
44
|
+
|
|
45
|
+
## Domain Layer Structure
|
|
46
|
+
|
|
47
|
+
### Organization
|
|
48
|
+
|
|
49
|
+
**Import From:** `src/auth/domain`
|
|
50
|
+
|
|
51
|
+
**Structure:**
|
|
52
|
+
- `entities/` - Business entities (AnonymousUser)
|
|
53
|
+
- `value-objects/` - Value objects (FirebaseAuthConfig)
|
|
54
|
+
- `errors/` - Domain errors (FirebaseAuthError)
|
|
55
|
+
|
|
56
|
+
**Principles:**
|
|
57
|
+
- No external dependencies (Firebase-free)
|
|
58
|
+
- Pure business logic
|
|
59
|
+
- Type-safe entities
|
|
60
|
+
- Clear boundaries
|
|
61
|
+
- Testable in isolation
|
|
62
|
+
|
|
63
|
+
## Entities
|
|
64
|
+
|
|
65
|
+
### AnonymousUser
|
|
66
|
+
|
|
67
|
+
**Import From:** `@umituz/react-native-firebase/auth` or `src/auth/domain`
|
|
68
|
+
|
|
69
|
+
**Purpose:** Represents an anonymous (guest) user in the system
|
|
70
|
+
|
|
71
|
+
**Properties:**
|
|
72
|
+
- `uid: string` - Unique user identifier
|
|
73
|
+
- `isAnonymous: true` - Always true for anonymous users
|
|
74
|
+
- `createdAt?: Date` - Account creation timestamp
|
|
75
|
+
|
|
76
|
+
**Type Guards:**
|
|
77
|
+
- `isAnonymousUser(user)` - Check if user is anonymous
|
|
78
|
+
- `isValidAnonymousUser(user)` - Validate anonymous user
|
|
79
|
+
- `toAnonymousUser(user)` - Convert to AnonymousUser entity
|
|
80
|
+
|
|
81
|
+
**Usage:**
|
|
82
|
+
- Identify anonymous users
|
|
83
|
+
- Validate user type
|
|
84
|
+
- Type-safe operations
|
|
85
|
+
- Business logic for guest users
|
|
86
|
+
|
|
87
|
+
**When to Use:**
|
|
88
|
+
- Checking user type
|
|
89
|
+
- Guest access logic
|
|
90
|
+
- Temporary session handling
|
|
91
|
+
- Account upgrade scenarios
|
|
92
|
+
|
|
93
|
+
**Business Rules:**
|
|
94
|
+
- Anonymous users have limited functionality
|
|
95
|
+
- Should prompt to upgrade to permanent account
|
|
96
|
+
- Track anonymous session duration
|
|
97
|
+
- Migrate data on upgrade
|
|
98
|
+
|
|
99
|
+
## Value Objects
|
|
100
|
+
|
|
101
|
+
### FirebaseAuthConfig
|
|
102
|
+
|
|
103
|
+
**Import From:** `@umituz/react-native-firebase/auth` or `src/auth/domain`
|
|
104
|
+
|
|
105
|
+
**Purpose:** Immutable configuration for Firebase Authentication
|
|
106
|
+
|
|
107
|
+
**Properties:**
|
|
108
|
+
- Configuration values for auth providers
|
|
109
|
+
- API keys and client IDs
|
|
110
|
+
- Environment-specific settings
|
|
111
|
+
|
|
112
|
+
**Characteristics:**
|
|
113
|
+
- Immutable value object
|
|
114
|
+
- Validated on creation
|
|
115
|
+
- Type-safe configuration
|
|
116
|
+
- Environment-aware
|
|
117
|
+
|
|
118
|
+
**When to Use:**
|
|
119
|
+
- Initializing auth services
|
|
120
|
+
- Configuring auth providers
|
|
121
|
+
- Environment-specific settings
|
|
122
|
+
- Auth service setup
|
|
123
|
+
|
|
124
|
+
## Domain Errors
|
|
125
|
+
|
|
126
|
+
### FirebaseAuthError
|
|
127
|
+
|
|
128
|
+
**Import From:** `@umituz/react-native-firebase/auth` or `src/auth/domain/errors`
|
|
129
|
+
|
|
130
|
+
**Purpose:** Base error class for all Firebase Auth errors
|
|
131
|
+
|
|
132
|
+
**Properties:**
|
|
133
|
+
- `code: string` - Error code for programmatic handling
|
|
134
|
+
- `message: string` - Human-readable error message
|
|
135
|
+
|
|
136
|
+
**Usage:**
|
|
137
|
+
- Throwing custom auth errors
|
|
138
|
+
- Type checking with instanceof
|
|
139
|
+
- Error code for conditional logic
|
|
140
|
+
- Structured error handling
|
|
141
|
+
|
|
142
|
+
**When to Use:**
|
|
143
|
+
- Auth operation failures
|
|
144
|
+
- Type-safe error handling
|
|
145
|
+
- User-friendly error messages
|
|
146
|
+
- Error logging and tracking
|
|
147
|
+
|
|
148
|
+
### FirebaseAuthInitializationError
|
|
149
|
+
|
|
150
|
+
**Import From:** `@umituz/react-native-firebase/auth` or `src/auth/domain/errors`
|
|
151
|
+
|
|
152
|
+
**Purpose:** Error thrown when Firebase Auth fails to initialize
|
|
153
|
+
|
|
154
|
+
**Extends:** FirebaseAuthError
|
|
155
|
+
|
|
156
|
+
**When to Use:**
|
|
157
|
+
- Auth initialization failures
|
|
158
|
+
- Configuration errors
|
|
159
|
+
- Firebase setup issues
|
|
160
|
+
|
|
161
|
+
## Common Mistakes to Avoid
|
|
162
|
+
|
|
163
|
+
1. ❌ Importing Firebase Auth in domain layer
|
|
164
|
+
- ✅ Keep domain Firebase-free
|
|
165
|
+
|
|
166
|
+
2. ❌ Anemic domain models
|
|
167
|
+
- ✅ Add behavior to entities
|
|
168
|
+
|
|
169
|
+
3. ❌ Business logic in infrastructure
|
|
170
|
+
- ✅ Put business logic in domain
|
|
171
|
+
|
|
172
|
+
4. ❌ Not validating business rules
|
|
173
|
+
- ✅ Validate in domain layer
|
|
174
|
+
|
|
175
|
+
5. ❌ Leaking domain logic
|
|
176
|
+
- ✅ Keep domain logic contained
|
|
177
|
+
|
|
178
|
+
## AI Agent Instructions
|
|
179
|
+
|
|
180
|
+
### When Creating Domain Entity
|
|
181
|
+
|
|
182
|
+
1. Define entity interface
|
|
183
|
+
2. Add business logic methods
|
|
184
|
+
3. Validate invariants
|
|
185
|
+
4. Keep Firebase-free
|
|
186
|
+
5. Export for infrastructure use
|
|
187
|
+
|
|
188
|
+
### When Creating Value Object
|
|
189
|
+
|
|
190
|
+
1. Identify configuration values
|
|
191
|
+
2. Create immutable type
|
|
192
|
+
3. Validate on creation
|
|
193
|
+
4. Provide factory methods
|
|
194
|
+
5. Use for configuration
|
|
195
|
+
|
|
196
|
+
### When Creating Domain Error
|
|
197
|
+
|
|
198
|
+
1. Extend base error class
|
|
199
|
+
2. Add error code
|
|
200
|
+
3. Provide clear message
|
|
201
|
+
4. Include context
|
|
202
|
+
5. Export for use
|
|
203
|
+
|
|
204
|
+
## Code Quality Standards
|
|
205
|
+
|
|
206
|
+
### Domain Layer
|
|
207
|
+
|
|
208
|
+
- No Firebase imports
|
|
209
|
+
- Pure TypeScript
|
|
210
|
+
- Business logic only
|
|
211
|
+
- Type-safe entities
|
|
212
|
+
- Clear interfaces
|
|
213
|
+
|
|
214
|
+
### Testing
|
|
215
|
+
|
|
216
|
+
- Test domain in isolation
|
|
217
|
+
- Mock infrastructure
|
|
218
|
+
- Test business rules
|
|
219
|
+
- Validate invariants
|
|
220
|
+
- Unit test coverage
|
|
221
|
+
|
|
222
|
+
## Related Documentation
|
|
223
|
+
|
|
224
|
+
- [Auth Module README](../../README.md)
|
|
225
|
+
- [Auth Infrastructure README](../../infrastructure/README.md)
|
|
226
|
+
- [Auth Errors README](../errors/README.md)
|
|
227
|
+
- [Anonymous User Entity README](../entities/README.md)
|
|
228
|
+
|
|
229
|
+
## Architecture
|
|
230
|
+
|
|
231
|
+
### Domain Layer Responsibilities
|
|
232
|
+
|
|
233
|
+
**What Domain Does:**
|
|
234
|
+
- Defines business entities
|
|
235
|
+
- Contains business logic
|
|
236
|
+
- Validates business rules
|
|
237
|
+
- Provides domain services
|
|
238
|
+
- Defines domain errors
|
|
239
|
+
|
|
240
|
+
**What Domain Doesn't Do:**
|
|
241
|
+
- No Firebase SDK usage
|
|
242
|
+
- No auth operations
|
|
243
|
+
- No HTTP requests
|
|
244
|
+
- No external integrations
|
|
245
|
+
- No UI concerns
|
|
246
|
+
|
|
247
|
+
### DDD Principles
|
|
248
|
+
|
|
249
|
+
**Strategic Patterns:**
|
|
250
|
+
- Entities (identity-based objects)
|
|
251
|
+
- Value Objects (immutable values)
|
|
252
|
+
- Domain Services (stateless operations)
|
|
253
|
+
- Aggregates (consistency boundaries)
|
|
254
|
+
- Repositories (infrastructure concern)
|
|
255
|
+
|
|
256
|
+
**Tactical Patterns:**
|
|
257
|
+
- Factory (creation)
|
|
258
|
+
- Strategy (algorithms)
|
|
259
|
+
- Specification (business rules)
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
**Last Updated:** 2025-01-08
|
|
264
|
+
**Maintainer:** Auth Module Team
|