@umituz/react-native-auth 3.4.33 → 3.4.34

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.
@@ -1,576 +1,520 @@
1
1
  # Infrastructure Layer
2
2
 
3
- React Native Auth package infrastructure layer. Contains implementations of application interfaces and external service integrations.
3
+ Implements application interfaces and handles external service integrations.
4
4
 
5
- ## Structure
5
+ ---
6
6
 
7
- ```
8
- infrastructure/
9
- ├── providers/
10
- │ └── FirebaseAuthProvider.ts # Firebase auth implementation
11
- ├── services/
12
- │ ├── AuthService.ts # Main auth service
13
- │ ├── initializeAuth.ts # Auth initialization
14
- │ ├── UserDocumentService.ts # User document management
15
- │ ├── AnonymousModeService.ts # Anonymous user service
16
- │ └── AuthEventService.ts # Event handling
17
- ├── adapters/
18
- │ └── StorageProviderAdapter.ts # Storage adapter
19
- └── utils/
20
- └── AuthValidation.ts # Validation utilities
21
- ```
7
+ ## Strategy
22
8
 
23
- ## Overview
9
+ **Purpose**: Provides concrete implementations of domain and application layer interfaces. Handles all external dependencies and integrations.
24
10
 
25
- The infrastructure layer implements the interfaces defined in the application layer and handles all external integrations:
11
+ **When to Use**:
12
+ - Understanding Firebase integration
13
+ - Implementing custom services
14
+ - Debugging infrastructure issues
15
+ - Learning about external dependencies
26
16
 
27
- - **Firebase Authentication**: Primary auth provider implementation
28
- - **Firestore**: User document storage
29
- - **Firebase Storage**: Profile photo storage
30
- - **Validation**: Input validation utilities
17
+ **Location**: `src/infrastructure/`
31
18
 
32
19
  ---
33
20
 
34
- # FirebaseAuthProvider
35
-
36
- Firebase Authentication implementation of `IAuthProvider`.
37
-
38
- ## Features
21
+ ## Structure
39
22
 
40
- - Email/Password authentication
41
- - Google sign-in
42
- - Apple sign-in
43
- - Anonymous authentication
44
- - User state management
23
+ ### Services
45
24
 
46
- ## Usage
25
+ **AuthService.ts** - Main authentication service
26
+ **Purpose**: Orchestrates all authentication operations
47
27
 
28
+ **IMPORT PATH**:
48
29
  ```typescript
49
- import { FirebaseAuthProvider } from '@umituz/react-native-auth';
50
- import { getAuth } from 'firebase/auth';
51
-
52
- const firebaseAuth = getAuth();
53
- const provider = new FirebaseAuthProvider(firebaseAuth);
54
-
55
- // Sign up
56
- const user = await provider.signUp({
57
- email: 'user@example.com',
58
- password: 'password123',
59
- displayName: 'John Doe',
60
- });
61
-
62
- // Sign in
63
- const user = await provider.signIn({
64
- email: 'user@example.com',
65
- password: 'password123',
66
- });
67
-
68
- // Sign out
69
- await provider.signOut();
70
-
71
- // Get current user
72
- const currentUser = provider.getCurrentUser();
30
+ import { AuthService, initializeAuth } from '@umituz/react-native-auth';
73
31
  ```
74
32
 
75
- ---
76
-
77
- # AuthService
33
+ **Rules**:
34
+ - MUST implement IAuthService interface
35
+ - MUST initialize before use
36
+ - MUST handle Firebase errors
37
+ - MUST create user documents
38
+ - MUST not expose Firebase internals
78
39
 
79
- Main authentication service that orchestrates all auth operations.
40
+ **MUST NOT**:
41
+ - Skip initialization
42
+ - Expose Firebase types
43
+ - Ignore error handling
44
+ - Create multiple instances
80
45
 
81
- ## Features
46
+ ---
82
47
 
83
- - User authentication flow
84
- - User document creation
85
- - Error handling
86
- - State management
48
+ ### UserDocumentService
87
49
 
88
- ## Usage
50
+ **Purpose**: Manages Firestore user documents
89
51
 
52
+ **IMPORT PATH**:
90
53
  ```typescript
91
54
  import {
92
- AuthService,
93
- initializeAuthService,
94
- getAuthService,
95
- resetAuthService,
55
+ ensureUserDocument,
56
+ markUserDeleted,
57
+ configureUserDocumentService
96
58
  } from '@umituz/react-native-auth';
97
-
98
- // Initialize (must be called once)
99
- initializeAuthService({
100
- firebaseAuth: getAuth(),
101
- onAuthStateChanged: (user) => {
102
- console.log('Auth state changed:', user);
103
- },
104
- });
105
-
106
- // Get service instance
107
- const authService = getAuthService();
108
-
109
- // Sign in
110
- const user = await authService.signIn({
111
- email: 'user@example.com',
112
- password: 'password123',
113
- });
114
-
115
- // Sign up
116
- const user = await authService.signUp({
117
- email: 'user@example.com',
118
- password: 'password123',
119
- displayName: 'John Doe',
120
- });
121
-
122
- // Sign out
123
- await authService.signOut();
124
-
125
- // Reset (testing only)
126
- resetAuthService();
127
59
  ```
128
60
 
129
- ## API
130
-
131
- ### Methods
132
-
133
- | Method | Parameters | Returns | Description |
134
- |--------|------------|---------|-------------|
135
- | `signIn` | `{ email, password }` | `Promise<AuthUser>` | Sign in with email/password |
136
- | `signUp` | `{ email, password, displayName? }` | `Promise<AuthUser>` | Create new account |
137
- | `signOut` | - | `Promise<void>` | Sign out current user |
138
- | `getCurrentUser` | - | `AuthUser \| null` | Get current user |
139
- | `sendPasswordResetEmail` | `email` | `Promise<void>` | Send password reset email |
61
+ **OPERATIONS**:
62
+ - `ensureUserDocument(user, data?)` - Create/retrieve user document
63
+ - `markUserDeleted(userId)` - Mark user as deleted
64
+ - `configureUserDocumentService(config)` - Configure service
65
+
66
+ **Rules**:
67
+ - MUST create document on registration
68
+ - MUST handle document existence
69
+ - MUST use server timestamps
70
+ - MUST support custom configuration
71
+ - MUST not delete documents permanently
72
+
73
+ **MUST NOT**:
74
+ - Skip document creation
75
+ - Overwrite existing data
76
+ - Use client timestamps
77
+ - Hardcode collection name
78
+
79
+ **CONFIGURATION**:
80
+ - `collection` - Firestore collection name (default: 'users')
81
+ - `timestamps` - Add createdAt/updatedAt fields
82
+ - `userData` - Custom fields to add
140
83
 
141
84
  ---
142
85
 
143
- # initializeAuth
144
-
145
- Initializes the authentication system and sets up Firebase Auth state listener.
146
-
147
- ## Features
148
-
149
- - Firebase Auth initialization
150
- - Auth state listener setup
151
- - Automatic user document creation
152
- - Error handling
86
+ ### AnonymousModeService
153
87
 
154
- ## Usage
155
-
156
- ### Basic Initialization
88
+ **Purpose**: Handles anonymous user authentication and upgrade
157
89
 
90
+ **IMPORT PATH**:
158
91
  ```typescript
159
- import { initializeAuth } from '@umituz/react-native-auth';
160
-
161
- function App() {
162
- useEffect(() => {
163
- const init = async () => {
164
- await initializeAuth({
165
- onAuthStateChanged: (user) => {
166
- console.log('Auth state changed:', user);
167
- },
168
- });
169
- };
170
-
171
- init();
172
- }, []);
173
-
174
- return <AppNavigator />;
175
- }
92
+ import { AnonymousModeService } from '@umituz/react-native-auth';
176
93
  ```
177
94
 
178
- ### With Navigation Integration
95
+ **OPERATIONS**:
96
+ - `signInAnonymously()` - Create anonymous user
97
+ - User upgrade via Firebase credential linking
98
+
99
+ **Rules**:
100
+ - MUST create temporary accounts
101
+ - MUST support upgrade path
102
+ - MUST warn about data loss
103
+ - MUST handle upgrade failures
104
+ - MUST not delete anonymous data
105
+
106
+ **MUST NOT**:
107
+ - Skip upgrade warnings
108
+ - Lose user data on upgrade
109
+ - Allow anonymous operations without warning
110
+ - Make anonymous permanent
111
+
112
+ **Constraints**:
113
+ - Anonymous users have limited functionality
114
+ - Data lost if sign out without upgrade
115
+ - Upgrade requires credentials
116
+ - Cannot revert to anonymous after upgrade
179
117
 
180
- ```typescript
181
- import { initializeAuth } from '@umituz/react-native-auth';
118
+ ---
182
119
 
183
- function App() {
184
- const navigation = useNavigation();
185
-
186
- useEffect(() => {
187
- initializeAuth({
188
- onAuthStateChanged: (user) => {
189
- if (user) {
190
- navigation.reset({
191
- index: 0,
192
- routes: [{ name: 'Home' }],
193
- });
194
- } else {
195
- navigation.reset({
196
- index: 0,
197
- routes: [{ name: 'Login' }],
198
- });
199
- }
200
- },
201
- onAuthError: (error) => {
202
- console.error('Auth error:', error);
203
- Alert.alert('Auth Error', error.message);
204
- },
205
- });
206
- }, []);
207
-
208
- return <NavigationContainer>{/* Routes */}</NavigationContainer>;
209
- }
210
- ```
120
+ ### AuthEventService
211
121
 
212
- ### Check Initialization Status
122
+ **Purpose**: Pub/sub system for authentication events
213
123
 
124
+ **IMPORT PATH**:
214
125
  ```typescript
215
- import { isAuthInitialized, resetAuthInitialization } from '@umituz/react-native-auth';
216
-
217
- if (isAuthInitialized()) {
218
- console.log('Auth is initialized');
219
- }
220
-
221
- // Reset (testing only)
222
- resetAuthInitialization();
126
+ import { AuthEventService } from '@umituz/react-native-auth';
223
127
  ```
224
128
 
225
- ---
226
-
227
- # UserDocumentService
228
-
229
- Manages user documents in Firestore.
129
+ **OPERATIONS**:
130
+ - `on(event, callback)` - Subscribe to event
131
+ - `emit(event, data)` - Emit event
132
+ - Returns unsubscribe function
133
+
134
+ **EVENTS**:
135
+ - `signIn` - User signed in (payload: AuthUser)
136
+ - `signUp` - New user registered (payload: AuthUser)
137
+ - `signOut` - User signed out (payload: undefined)
138
+ - `authStateChanged` - Auth state changed (payload: AuthUser | null)
139
+
140
+ **Rules**:
141
+ - MUST emit events on state changes
142
+ - MUST allow multiple subscribers
143
+ - MUST provide unsubscribe function
144
+ - MUST not throw in event handlers
145
+ - MUST handle subscriber errors
146
+
147
+ **MUST NOT**:
148
+ - Skip critical events
149
+ - Block on event handlers
150
+ - Throw unhandled errors
151
+ - Memory leak subscribers
230
152
 
231
- ## Features
232
-
233
- - Automatic user document creation
234
- - User data updates
235
- - Account deletion marking
236
- - Custom configuration
153
+ ---
237
154
 
238
- ## Usage
155
+ ### StorageProviderAdapter
239
156
 
240
- ### Ensure User Document
157
+ **Purpose**: Adapter interface for storage providers
241
158
 
159
+ **IMPORT PATH**:
242
160
  ```typescript
243
- import { ensureUserDocument } from '@umituz/react-native-auth';
244
-
245
- // After user signs in/up, ensure document exists
246
- const user = await signInWithEmailAndPassword(auth, email, password);
247
- await ensureUserDocument(user);
161
+ import {
162
+ createStorageProvider,
163
+ StorageProviderAdapter
164
+ } from '@umituz/react-native-auth';
248
165
  ```
249
166
 
250
- ### Mark User as Deleted
167
+ **INTERFACE METHODS**:
168
+ - `getItem(key)` - Retrieve value
169
+ - `setItem(key, value)` - Store value
170
+ - `removeItem(key)` - Delete value
171
+
172
+ **Rules**:
173
+ - MUST implement all methods
174
+ - MUST handle async operations
175
+ - MUST return null for missing keys
176
+ - MUST handle storage errors
177
+ - MUST support string values only
178
+
179
+ **MUST NOT**:
180
+ - Throw for missing keys
181
+ - Skip error handling
182
+ - Assume synchronous operations
183
+ - Store non-string values
184
+
185
+ **IMPLEMENTATIONS**:
186
+ - AsyncStorage
187
+ - MMKV
188
+ - SecureStorage
189
+ - Custom implementations
251
190
 
252
- ```typescript
253
- import { markUserDeleted } from '@umituz/react-native-auth';
191
+ ---
254
192
 
255
- // When user deletes account
256
- await markUserDeleted(userId);
257
- ```
193
+ ## Validation Utilities
194
+
195
+ ### AuthValidation
258
196
 
259
- ### Configure Service
197
+ **Purpose**: Input validation for authentication
260
198
 
199
+ **IMPORT PATH**:
261
200
  ```typescript
262
- import { configureUserDocumentService } from '@umituz/react-native-auth';
263
-
264
- configureUserDocumentService({
265
- collection: 'customers', // Default: 'users'
266
- timestamps: true, // Add createdAt, updatedAt
267
- userData: {
268
- source: 'app',
269
- version: '1.0.0',
270
- },
271
- });
201
+ import {
202
+ validateEmail,
203
+ validatePasswordForLogin,
204
+ validatePasswordForRegister,
205
+ validatePasswordConfirmation,
206
+ validateDisplayName,
207
+ DEFAULT_VAL_CONFIG
208
+ } from '@umituz/react-native-auth';
272
209
  ```
273
210
 
274
- ### Custom User Data
211
+ **VALIDATORS**:
212
+ - `validateEmail(email)` - Email format validation
213
+ - `validatePasswordForLogin(password)` - Login password check
214
+ - `validatePasswordForRegister(password)` - Registration password complexity
215
+ - `validatePasswordConfirmation(password, confirmation)` - Password match
216
+ - `validateDisplayName(name)` - Display name validation
275
217
 
218
+ **RETURN TYPE**:
276
219
  ```typescript
277
- await ensureUserDocument(user, {
278
- role: 'premium',
279
- subscription: 'monthly',
280
- preferences: {
281
- newsletter: true,
282
- notifications: true,
283
- },
284
- });
220
+ {
221
+ isValid: boolean;
222
+ error?: string;
223
+ // Additional fields for specific validators
224
+ }
285
225
  ```
286
226
 
287
- ---
288
-
289
- # AnonymousModeService
227
+ **Rules**:
228
+ - MUST return validation result object
229
+ - MUST provide error messages
230
+ - MUST use configurable rules
231
+ - MUST support internationalization
232
+ - MUST not throw for invalid input
233
+
234
+ **MUST NOT**:
235
+ - Return boolean only
236
+ - Skip error messages
237
+ - Hardcode validation rules
238
+ - Throw on validation failure
239
+
240
+ **DEFAULT CONFIG**:
241
+ - `password.minLength` - 8 characters
242
+ - `password.requireUppercase` - true
243
+ - `password.requireLowercase` - true
244
+ - `password.requireNumber` - true
245
+ - `password.requireSpecialChar` - true
290
246
 
291
- Handles anonymous user authentication.
247
+ ---
292
248
 
293
- ## Features
249
+ ## Firebase Integration
294
250
 
295
- - Anonymous account creation
296
- - Anonymous user upgrade to regular account
297
- - Anonymous state management
251
+ ### FirebaseAuthProvider
298
252
 
299
- ## Usage
253
+ **Purpose**: Firebase Authentication implementation
300
254
 
301
- ```typescript
302
- import { AnonymousModeService } from '@umituz/react-native-auth';
255
+ **Location**: `providers/FirebaseAuthProvider.ts`
303
256
 
304
- const anonymousService = new AnonymousModeService();
257
+ **Rules**:
258
+ - MUST implement IAuthProvider
259
+ - MUST wrap Firebase SDK
260
+ - MUST handle Firebase lifecycle
261
+ - MUST map to domain entities
262
+ - MUST convert Firebase errors
305
263
 
306
- // Sign in anonymously
307
- const user = await anonymousService.signInAnonymously();
308
- console.log('Anonymous user:', user.uid);
309
-
310
- // Convert anonymous user to regular user
311
- const credential = EmailAuthProvider.credential(email, password);
312
- await linkWithCredential(user, credential);
313
- console.log('User upgraded:', user.email);
314
- ```
264
+ **MUST NOT**:
265
+ - Expose Firebase types
266
+ - Bypass error mapping
267
+ - Skip Firebase initialization
268
+ - Ignore auth state changes
315
269
 
316
270
  ---
317
271
 
318
- # AuthEventService
319
-
320
- Manages authentication events and provides pub/sub functionality.
321
-
322
- ## Features
272
+ ### Error Mapping
323
273
 
324
- - Event emission
325
- - Event subscription
326
- - Type-safe events
327
-
328
- ## Usage
274
+ **Purpose**: Convert Firebase errors to domain errors
329
275
 
276
+ **IMPORT PATH**:
330
277
  ```typescript
331
- import { AuthEventService } from '@umituz/react-native-auth';
332
-
333
- const eventService = new AuthEventService();
334
-
335
- // Subscribe to events
336
- const unsubscribe = eventService.on('signIn', (user) => {
337
- console.log('User signed in:', user);
338
- });
339
-
340
- // Emit events
341
- eventService.emit('signIn', user);
342
-
343
- // Unsubscribe
344
- unsubscribe();
278
+ import { mapFirebaseError } from '@umituz/react-native-auth';
345
279
  ```
346
280
 
347
- ### Available Events
348
-
349
- | Event | Payload | Description |
350
- |-------|---------|-------------|
351
- | `signIn` | `AuthUser` | User signed in |
352
- | `signUp` | `AuthUser` | New user registered |
353
- | `signOut` | `undefined` | User signed out |
354
- | `authStateChanged` | `AuthUser \| null` | Auth state changed |
281
+ **MAPPING**:
282
+ - `auth/user-not-found` → AuthUserNotFoundError
283
+ - `auth/wrong-password` AuthWrongPasswordError
284
+ - `auth/email-already-in-use` → AuthEmailAlreadyInUseError
285
+ - `auth/weak-password` AuthWeakPasswordError
286
+ - `auth/invalid-email` AuthInvalidEmailError
287
+ - `auth/network-request-failed` AuthNetworkError
288
+
289
+ **Rules**:
290
+ - MUST map all Firebase errors
291
+ - MUST preserve error context
292
+ - MUST use domain error types
293
+ - MUST not lose error information
294
+ - MUST handle unknown errors
295
+
296
+ **MUST NOT**:
297
+ - Throw raw Firebase errors
298
+ - Skip error mapping
299
+ - Lose error context
300
+ - Use generic error type
355
301
 
356
302
  ---
357
303
 
358
- # StorageProviderAdapter
304
+ ## Initialization
359
305
 
360
- Adapter for storage providers (AsyncStorage, MMKV, etc.).
306
+ ### initializeAuth
361
307
 
362
- ## Usage
308
+ **Purpose**: Initialize authentication system
363
309
 
310
+ **IMPORT PATH**:
364
311
  ```typescript
365
- import {
366
- createStorageProvider,
367
- StorageProviderAdapter,
368
- } from '@umituz/react-native-auth';
312
+ import { initializeAuth } from '@umituz/react-native-auth';
313
+ ```
369
314
 
370
- // Custom implementation
371
- class CustomStorageAdapter implements StorageProviderAdapter {
372
- async getItem(key: string): Promise<string | null> {
373
- return await AsyncStorage.getItem(key);
374
- }
315
+ **PARAMETERS**:
316
+ - `onAuthStateChanged` - Auth state callback
317
+ - `onAuthError` - Error callback (optional)
375
318
 
376
- async setItem(key: string, value: string): Promise<void> {
377
- await AsyncStorage.setItem(key, value);
378
- }
319
+ **Rules**:
320
+ - MUST call once at app startup
321
+ - MUST wait for initialization
322
+ - MUST handle initialization errors
323
+ - MUST not call multiple times
324
+ - MUST check initialization status
379
325
 
380
- async removeItem(key: string): Promise<void> {
381
- await AsyncStorage.removeItem(key);
382
- }
383
- }
326
+ **MUST NOT**:
327
+ - Skip initialization
328
+ - Call in components
329
+ - Initialize multiple times
330
+ - Ignore initialization status
384
331
 
385
- // Create provider
386
- const storageProvider = createStorageProvider(new CustomStorageAdapter());
387
- ```
332
+ **CHECK FUNCTIONS**:
333
+ - `isAuthInitialized()` - Check if initialized
334
+ - `resetAuthInitialization()` - Reset (testing only)
388
335
 
389
336
  ---
390
337
 
391
- # Validation Utilities
338
+ ## Configuration
392
339
 
393
- Input validation utilities for authentication.
340
+ ### Service Configuration
394
341
 
395
- ## Available Validators
342
+ **AuthService Configuration**:
343
+ - Firebase Auth instance
344
+ - Auth state callbacks
345
+ - Error handlers
396
346
 
397
- ```typescript
398
- import {
399
- validateEmail,
400
- validatePasswordForLogin,
401
- validatePasswordForRegister,
402
- validatePasswordConfirmation,
403
- validateDisplayName,
404
- DEFAULT_VAL_CONFIG,
405
- } from '@umituz/react-native-auth';
406
- ```
347
+ **UserDocumentService Configuration**:
348
+ - Collection name
349
+ - Timestamps
350
+ - Custom user data
407
351
 
408
- ### Email Validation
352
+ **Validation Configuration**:
353
+ - Password requirements
354
+ - Email validation rules
355
+ - Display name constraints
409
356
 
410
- ```typescript
411
- const result = validateEmail('test@example.com');
412
- // { isValid: true }
357
+ **Rules**:
358
+ - MUST configure before use
359
+ - MUST use valid configuration
360
+ - MUST handle config errors
361
+ - MUST not change after initialization
362
+ - MUST validate configuration
413
363
 
414
- const result = validateEmail('invalid-email');
415
- // { isValid: false, error: 'Invalid email format' }
416
- ```
364
+ **MUST NOT**:
365
+ - Skip configuration
366
+ - Use invalid config
367
+ - Change after initialization
368
+ - Ignore config errors
417
369
 
418
- ### Password Validation (Login)
370
+ ---
419
371
 
420
- ```typescript
421
- const result = validatePasswordForLogin('password123');
422
- // { isValid: true }
372
+ ## Best Practices
423
373
 
424
- const result = validatePasswordForLogin('');
425
- // { isValid: false, error: 'Password is required' }
426
- ```
374
+ ### Initialization
427
375
 
428
- ### Password Validation (Register)
376
+ **MUST**:
377
+ - Initialize at app root
378
+ - Wait for initialization
379
+ - Handle initialization errors
380
+ - Check initialization status
381
+ - Configure properly
429
382
 
430
- ```typescript
431
- const result = validatePasswordForRegister('MyPass123!');
432
- // {
433
- // isValid: true,
434
- // requirements: {
435
- // hasMinLength: true,
436
- // hasUppercase: true,
437
- // hasLowercase: true,
438
- // hasNumber: true,
439
- // hasSpecialChar: true
440
- // }
441
- // }
442
-
443
- const result = validatePasswordForRegister('weak');
444
- // {
445
- // isValid: false,
446
- // requirements: { ... },
447
- // error: 'Password does not meet requirements'
448
- // }
449
- ```
383
+ **MUST NOT**:
384
+ - Initialize in components
385
+ - Skip initialization check
386
+ - Ignore initialization errors
387
+ - Initialize multiple times
388
+ - Use default config blindly
450
389
 
451
- ### Password Confirmation
390
+ ---
452
391
 
453
- ```typescript
454
- const result = validatePasswordConfirmation('password123', 'password123');
455
- // { isValid: true, matches: true }
392
+ ### Error Handling
456
393
 
457
- const result = validatePasswordConfirmation('password123', 'different');
458
- // { isValid: false, matches: false, error: 'Passwords do not match' }
459
- ```
394
+ **MUST**:
395
+ - Map Firebase errors to domain
396
+ - Provide context
397
+ - Log appropriately
398
+ - Show user-friendly messages
399
+ - Handle network failures
460
400
 
461
- ### Display Name Validation
401
+ **MUST NOT**:
402
+ - Expose Firebase errors
403
+ - Show technical details
404
+ - Skip error mapping
405
+ - Suppress errors
406
+ - Log sensitive data
462
407
 
463
- ```typescript
464
- const result = validateDisplayName('John Doe');
465
- // { isValid: true }
408
+ ---
466
409
 
467
- const result = validateDisplayName('');
468
- // { isValid: false, error: 'Display name is required' }
469
- ```
410
+ ### User Documents
470
411
 
471
- ### Custom Validation Config
412
+ **MUST**:
413
+ - Create document on registration
414
+ - Use server timestamps
415
+ - Handle existing documents
416
+ - Configure collection name
417
+ - Add custom fields
472
418
 
473
- ```typescript
474
- import { DEFAULT_VAL_CONFIG } from '@umituz/react-native-auth';
475
-
476
- // Default config
477
- DEFAULT_VAL_CONFIG;
478
- // {
479
- // password: {
480
- // minLength: 8,
481
- // requireUppercase: true,
482
- // requireLowercase: true,
483
- // requireNumber: true,
484
- // requireSpecialChar: true,
485
- // }
486
- // }
487
- ```
419
+ **MUST NOT**:
420
+ - Skip document creation
421
+ - Overwrite data
422
+ - Use client timestamps
423
+ - Hardcode collection name
424
+ - Delete documents permanently
488
425
 
489
426
  ---
490
427
 
491
- # Error Handling
428
+ ## Security
492
429
 
493
- ## Firebase Error Mapping
430
+ ### Data Protection
494
431
 
495
- ```typescript
496
- import {
497
- mapFirebaseError,
498
- AuthUserNotFoundError,
499
- AuthWrongPasswordError,
500
- } from '@umituz/react-native-auth';
432
+ **MUST**:
433
+ - Validate all inputs
434
+ - Use HTTPS
435
+ - Handle tokens properly
436
+ - Secure credentials
437
+ - Log appropriately
501
438
 
502
- try {
503
- await signInWithEmailAndPassword(auth, email, password);
504
- } catch (error) {
505
- const authError = mapFirebaseError(error);
439
+ **MUST NOT**:
440
+ - Log passwords
441
+ - Expose tokens
442
+ - Skip validation
443
+ - Store credentials insecurely
444
+ - Log sensitive data
506
445
 
507
- if (authError instanceof AuthUserNotFoundError) {
508
- Alert.alert('Error', 'User not found');
509
- } else if (authError instanceof AuthWrongPasswordError) {
510
- Alert.alert('Error', 'Wrong password');
511
- }
512
- }
513
- ```
446
+ ---
447
+
448
+ ### Firebase Security
449
+
450
+ **MUST**:
451
+ - Use Firebase security rules
452
+ - Enable required providers
453
+ - Configure properly
454
+ - Monitor usage
455
+ - Handle errors
456
+
457
+ **MUST NOT**:
458
+ - Skip Firebase setup
459
+ - Ignore security rules
460
+ - Expose API keys
461
+ - Leave unconfigured
462
+ - Ignore Firebase errors
514
463
 
515
464
  ---
516
465
 
517
- # Best Practices
466
+ ## Constraints
518
467
 
519
- ## 1. Initialize Early
468
+ ### Platform Limitations
520
469
 
521
- ```typescript
522
- // ✅ Good - Initialize in app root
523
- function App() {
524
- useEffect(() => {
525
- initializeAuth();
526
- }, []);
470
+ **Firebase Dependencies**:
471
+ - Requires Firebase project
472
+ - Requires Firebase SDK
473
+ - Requires network connection
474
+ - Platform-specific features
527
475
 
528
- return <Navigator />;
529
- }
476
+ **Rules**:
477
+ - MUST check platform availability
478
+ - MUST handle platform differences
479
+ - MUST not crash on unsupported
480
+ - MUST document platform constraints
530
481
 
531
- // ❌ Bad - Initialize in component
532
- function LoginComponent() {
533
- useEffect(() => {
534
- initializeAuth(); // Too late!
535
- }, []);
536
- }
537
- ```
482
+ ---
538
483
 
539
- ## 2. Handle Initialization State
484
+ ### Network Requirements
540
485
 
541
- ```typescript
542
- function App() {
543
- const [isInitialized, setIsInitialized] = useState(false);
486
+ **MUST**:
487
+ - Handle network failures
488
+ - Provide offline fallback
489
+ - Show network errors
490
+ - Allow retry
491
+ - Check connectivity
544
492
 
545
- useEffect(() => {
546
- initializeAuth().then(() => setIsInitialized(true));
547
- }, []);
493
+ **MUST NOT**:
494
+ - Assume always online
495
+ - Skip network errors
496
+ - Crash on network failure
497
+ - Prevent offline usage
548
498
 
549
- if (!isInitialized) {
550
- return <LoadingScreen />;
551
- }
499
+ ---
552
500
 
553
- return <AppNavigator />;
554
- }
555
- ```
501
+ ## Related Modules
556
502
 
557
- ## 3. Check Auth Before Operations
503
+ - **Domain** (`../domain/README.md`) - AuthUser entity, errors, config
504
+ - **Application** (`../application/README.md`) - Interfaces and ports
505
+ - **Presentation** (`../presentation/README.md`) - UI components
558
506
 
559
- ```typescript
560
- async function protectedOperation() {
561
- const authService = getAuthService();
562
- const user = authService.getCurrentUser();
507
+ ---
563
508
 
564
- if (!user) {
565
- throw new Error('User not authenticated');
566
- }
509
+ ## Service Documentation
567
510
 
568
- // Proceed with operation
569
- }
570
- ```
511
+ ### Detailed Service Docs
571
512
 
572
- ## Related Modules
513
+ **See**: `services/README.md` for detailed service documentation
573
514
 
574
- - **[Domain](../domain/README.md)** - Domain entities
575
- - **[Application](../application/README.md)** - Application interfaces
576
- - **[Presentation](../presentation/README.md)** - UI components and hooks
515
+ **Services Covered**:
516
+ - AuthService
517
+ - UserDocumentService
518
+ - AnonymousModeService
519
+ - AuthEventService
520
+ - Validation utilities