@umituz/react-native-auth 3.4.32 → 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.
Files changed (30) hide show
  1. package/README.md +347 -348
  2. package/package.json +2 -3
  3. package/src/application/README.md +323 -442
  4. package/src/domain/ConfigAndErrors.md +296 -431
  5. package/src/domain/README.md +361 -210
  6. package/src/domain/entities/AuthUser.md +231 -372
  7. package/src/domain/entities/UserProfile.md +271 -441
  8. package/src/index.ts +35 -0
  9. package/src/infrastructure/README.md +388 -444
  10. package/src/infrastructure/services/README.md +386 -312
  11. package/src/infrastructure/utils/validation/BaseValidators.ts +35 -0
  12. package/src/infrastructure/utils/validation/CollectionValidators.ts +56 -0
  13. package/src/infrastructure/utils/validation/DateValidators.ts +63 -0
  14. package/src/infrastructure/utils/validation/FormValidators.ts +22 -0
  15. package/src/infrastructure/utils/validation/NumberValidators.ts +55 -0
  16. package/src/infrastructure/utils/validation/StringValidators.ts +55 -0
  17. package/src/infrastructure/utils/validation/sanitization.ts +98 -0
  18. package/src/infrastructure/utils/validation/types.ts +15 -0
  19. package/src/presentation/README.md +631 -563
  20. package/src/presentation/components/ProfileComponents.md +307 -504
  21. package/src/presentation/components/README.md +254 -92
  22. package/src/presentation/hooks/README.md +247 -83
  23. package/src/presentation/hooks/useAccountManagement.md +295 -344
  24. package/src/presentation/hooks/useAuth.md +271 -227
  25. package/src/presentation/hooks/useAuthBottomSheet.md +417 -367
  26. package/src/presentation/hooks/useAuthRequired.md +308 -194
  27. package/src/presentation/hooks/useProfileUpdate.md +251 -279
  28. package/src/presentation/hooks/useSocialLogin.md +312 -287
  29. package/src/presentation/hooks/useUserProfile.md +259 -192
  30. package/src/presentation/screens/README.md +151 -153
@@ -1,293 +1,444 @@
1
1
  # Domain Layer
2
2
 
3
- React Native Auth paketinin domain katmanı. İş kurallarını, domain entity'lerini ve value object'leri içerir.
3
+ Core business logic, domain entities, value objects, and domain rules.
4
4
 
5
- ## Yapı
5
+ ---
6
6
 
7
- ```
8
- domain/
9
- ├── entities/
10
- │ ├── AuthUser.ts # Authentication kullanıcısı
11
- │ └── UserProfile.ts # Kullanıcı profili
12
- ├── value-objects/
13
- │ └── AuthConfig.ts # Auth konfigürasyonu
14
- ├── errors/
15
- │ └── AuthError.ts # Auth hataları
16
- └── utils/
17
- ├── anonymousNameGenerator.ts # Anonymous isim oluşturucu
18
- └── migration.ts # Veri taşıma
19
- ```
7
+ ## Strategy
8
+
9
+ **Purpose**: Contains business rules and domain models independent of external dependencies. Represents the core authentication logic.
10
+
11
+ **When to Use**:
12
+ - Understanding business rules
13
+ - Working with domain entities
14
+ - Implementing validation
15
+ - Learning about data structures
16
+
17
+ **Location**: `src/domain/`
18
+
19
+ ---
20
+
21
+ ## Structure
22
+
23
+ ### Entities
24
+
25
+ **entities/AuthUser.ts** - Provider-agnostic user entity
26
+ **entities/UserProfile.ts** - User profile for Firestore
27
+
28
+ ### Value Objects
29
+
30
+ **value-objects/AuthConfig.ts** - Authentication configuration
20
31
 
21
- ## Entities
32
+ ### Errors
33
+
34
+ **errors/AuthError.ts** - Domain-specific error hierarchy
35
+
36
+ ### Utils
37
+
38
+ **utils/anonymousNameGenerator.ts** - Anonymous name generation
39
+ **utils/migration.ts** - Data migration utilities
40
+
41
+ ---
42
+
43
+ ## Domain Entities
22
44
 
23
45
  ### AuthUser
24
46
 
25
- Authentication işlemleri için kullanıcı entity'si.
47
+ **PURPOSE**: Provider-agnostic user entity for authentication
26
48
 
49
+ **IMPORT PATH**:
27
50
  ```typescript
28
51
  import type { AuthUser } from '@umituz/react-native-auth';
29
-
30
- const user: AuthUser = {
31
- uid: 'user-123',
32
- email: 'user@example.com',
33
- displayName: 'John Doe',
34
- photoURL: 'https://...',
35
- isAnonymous: false,
36
- provider: 'google',
37
- emailVerified: true,
38
- };
39
52
  ```
40
53
 
41
- **Özellikler:**
42
- - Firebase User ile uyumlu
43
- - Provider bilgisi
44
- - Anonymous kontrolü
45
- - Email verification durumu
54
+ **PROPERTIES**:
55
+ - `uid: string` - Unique user identifier
56
+ - `email: string | null` - Email address
57
+ - `displayName: string | null` - Display name
58
+ - `photoURL: string | null` - Profile photo URL
59
+ - `isAnonymous: boolean` - Anonymous flag
60
+ - `emailVerified: boolean` - Email verification status
61
+ - `provider: AuthProviderType` - Auth provider type
46
62
 
47
- **Kullanım:**
48
- ```typescript
49
- function getUserDisplayName(user: AuthUser): string {
50
- return user.displayName || user.email || 'Anonymous';
51
- }
63
+ **Rules**:
64
+ - MUST have unique uid
65
+ - MUST NOT have empty uid
66
+ - Anonymous users have null email
67
+ - Provider indicates auth method
68
+ - Email can be null for social auth
52
69
 
53
- function isSocialLogin(user: AuthUser): boolean {
54
- return user.provider === 'google' || user.provider === 'apple';
55
- }
56
- ```
70
+ **MUST NOT**:
71
+ - Allow empty uid
72
+ - Change uid after creation
73
+ - Have anonymous user with email
74
+ - Use invalid provider type
75
+
76
+ **Documentation**: `entities/AuthUser.md`
77
+
78
+ ---
57
79
 
58
80
  ### UserProfile
59
81
 
60
- Kullanıcı profili entity'si.
82
+ **PURPOSE**: User profile entity for Firestore document storage
61
83
 
84
+ **IMPORT PATH**:
62
85
  ```typescript
63
86
  import type { UserProfile } from '@umituz/react-native-auth';
64
-
65
- const profile: UserProfile = {
66
- displayName: 'John Doe',
67
- photoURL: 'https://...',
68
- bio: 'Software developer',
69
- location: 'Istanbul',
70
- website: 'https://johndoe.com',
71
- };
72
87
  ```
73
88
 
74
- **Güncelleme:**
75
- ```typescript
76
- async function updateProfile(userId: string, updates: UpdateProfileParams) {
77
- await updateDoc(doc(db, 'users', userId), updates);
78
- }
79
- ```
89
+ **PROPERTIES**:
90
+ - `uid: string` - User ID
91
+ - `email: string | null` - Email address
92
+ - `displayName: string | null` - Display name
93
+ - `photoURL: string | null` - Profile photo URL
94
+ - `isAnonymous: boolean` - Anonymous flag
95
+ - `createdAt: Date | null` - Account creation date
96
+ - `lastLoginAt: Date | null` - Last login timestamp
97
+
98
+ **Rules**:
99
+ - MUST create on user registration
100
+ - MUST include uid
101
+ - MUST set initial timestamps
102
+ - MUST validate updates
103
+ - MUST handle partial updates
104
+
105
+ **MUST NOT**:
106
+ - Delete existing profiles
107
+ - Skip validation
108
+ - Use client timestamps
109
+ - Overwrite without checking
110
+
111
+ **Documentation**: `entities/UserProfile.md`
112
+
113
+ ---
80
114
 
81
115
  ## Value Objects
82
116
 
83
117
  ### AuthConfig
84
118
 
85
- Authentication konfigürasyonu.
119
+ **PURPOSE**: Authentication configuration value object
86
120
 
121
+ **IMPORT PATH**:
87
122
  ```typescript
88
- import { AuthConfig, DEFAULT_AUTH_CONFIG } from '@umituz/react-native-auth';
89
-
90
- const config: AuthConfig = {
91
- password: {
92
- minLength: 8,
93
- requireUppercase: true,
94
- requireLowercase: true,
95
- requireNumbers: true,
96
- requireSpecialChars: true,
97
- },
98
- social: {
99
- google: {
100
- iosClientId: '...',
101
- webClientId: '...',
102
- },
103
- apple: {
104
- enabled: true,
105
- },
106
- },
107
- };
123
+ import type { AuthConfig } from '@umituz/react-native-auth';
108
124
  ```
109
125
 
110
- ## Errors
126
+ **COMPONENTS**:
127
+ - `password: PasswordConfig` - Password requirements
128
+ - `social?: SocialAuthConfig` - Social provider config
129
+
130
+ **PasswordConfig**:
131
+ - `minLength: number` - Minimum password length
132
+ - `requireUppercase: boolean` - Require uppercase
133
+ - `requireLowercase: boolean` - Require lowercase
134
+ - `requireNumber: boolean` - Require number
135
+ - `requireSpecialChar: boolean` - Require special character
136
+
137
+ **Rules**:
138
+ - MUST set minLength between 4-128
139
+ - MUST validate password against config
140
+ - MUST provide password config
141
+ - MAY provide social config
142
+
143
+ **MUST NOT**:
144
+ - Set minLength < 4
145
+ - Set minLength > 128
146
+ - Skip validation
147
+
148
+ **Documentation**: `ConfigAndErrors.md`
149
+
150
+ ---
151
+
152
+ ## Domain Errors
111
153
 
112
154
  ### AuthError Hierarchy
113
155
 
156
+ **PURPOSE**: Type-safe error handling with clear error types
157
+
158
+ **IMPORT PATH**:
114
159
  ```typescript
115
160
  import {
116
161
  AuthError,
117
- AuthInitializationError,
118
- AuthConfigurationError,
119
- AuthValidationError,
120
- AuthNetworkError,
121
162
  AuthUserNotFoundError,
122
163
  AuthWrongPasswordError,
123
164
  AuthEmailAlreadyInUseError,
124
165
  AuthWeakPasswordError,
125
166
  AuthInvalidEmailError,
167
+ AuthNetworkError
126
168
  } from '@umituz/react-native-auth';
127
169
  ```
128
170
 
129
- **Hata Yakalama:**
130
- ```typescript
131
- try {
132
- await signIn({ email, password });
133
- } catch (error) {
134
- if (error instanceof AuthUserNotFoundError) {
135
- // Kullanıcı bulunamadı
136
- } else if (error instanceof AuthWrongPasswordError) {
137
- // Şifre hatalı
138
- } else if (error instanceof AuthNetworkError) {
139
- // Network hatası
140
- }
141
- }
142
- ```
171
+ **ERROR TYPES**:
172
+ - `AuthUserNotFoundError` - User not found
173
+ - `AuthWrongPasswordError` - Incorrect password
174
+ - `AuthEmailAlreadyInUseError` - Email already registered
175
+ - `AuthWeakPasswordError` - Password too weak
176
+ - `AuthInvalidEmailError` - Invalid email format
177
+ - `AuthNetworkError` - Network connection failure
178
+
179
+ **Rules**:
180
+ - MUST use domain errors (not Firebase)
181
+ - MUST map Firebase errors to domain
182
+ - MUST preserve error context
183
+ - MUST show user-friendly messages
184
+ - MUST not expose system details
185
+
186
+ **MUST NOT**:
187
+ - Throw Firebase errors directly
188
+ - Expose error codes
189
+ - Show stack traces
190
+ - Reveal sensitive information
191
+
192
+ **Documentation**: `ConfigAndErrors.md`
193
+
194
+ ---
143
195
 
144
- ## Utils
196
+ ## Domain Utilities
145
197
 
146
198
  ### Anonymous Name Generator
147
199
 
148
- Anonymous kullanıcılar için rastgele isim oluşturur.
200
+ **PURPOSE**: Generate random names for anonymous users
149
201
 
202
+ **IMPORT PATH**:
150
203
  ```typescript
151
204
  import {
152
205
  generateAnonymousName,
153
206
  getAnonymousDisplayName
154
207
  } from '@umituz/react-native-auth';
208
+ ```
155
209
 
156
- const name1 = generateAnonymousName('user-123');
157
- // "User_Witty_Badger_1234"
210
+ **FUNCTIONS**:
211
+ - `generateAnonymousName(uid, config?)` - Generate anonymous name
212
+ - `getAnonymousDisplayName(uid)` - Get display name only
158
213
 
159
- const name2 = generateAnonymousName('user-456', {
160
- prefix: 'Guest',
161
- adjectiveCount: 1,
162
- nounCount: 1,
163
- });
164
- // "Guest_Clever_Fox_456"
214
+ **CONFIGURATION**:
215
+ - `prefix` - Name prefix (default: 'User')
216
+ - `adjectiveCount` - Number of adjectives (default: 2)
217
+ - `nounCount` - Number of nouns (default: 1)
218
+ - `showNumbers` - Include numbers (default: true)
165
219
 
166
- const displayName = getAnonymousDisplayName('user-123');
167
- // "Witty Badger"
168
- ```
220
+ **Rules**:
221
+ - MUST be deterministic for same uid
222
+ - MUST generate unique names
223
+ - MUST be human-readable
224
+ - MUST not contain offensive words
225
+ - MUST support custom configuration
169
226
 
170
- **Konfigürasyon:**
171
- ```typescript
172
- interface AnonymousNameConfig {
173
- prefix?: string; // Varsayılan: 'User'
174
- adjectiveCount?: number; // Varsayılan: 2
175
- nounCount?: number; // Varsayılan: 1
176
- showNumbers?: boolean; // Varsayılan: true
177
- }
178
- ```
227
+ **MUST NOT**:
228
+ - Generate duplicate names
229
+ - Use offensive language
230
+ - Be non-deterministic
231
+ - Ignore configuration
179
232
 
180
- ### Migration
233
+ ---
181
234
 
182
- Kullanıcı verilerini taşımak için utility.
235
+ ### Migration Utilities
183
236
 
184
- ```typescript
185
- import { migrateUserData, configureMigration } from '@umituz/react-native-auth';
186
-
187
- // Migration konfigürasyonu
188
- configureMigration({
189
- from: 'legacy_users',
190
- to: 'users',
191
- transform: (legacyData) => ({
192
- displayName: legacyData.name,
193
- email: legacyData.email_address,
194
- createdAt: legacyData.joined_at,
195
- }),
196
- });
197
-
198
- // Migration çalıştırma
199
- await migrateUserData(userId);
200
- ```
237
+ **PURPOSE**: Migrate user data between collections
201
238
 
202
- **Tam Örnek:**
239
+ **IMPORT PATH**:
203
240
  ```typescript
204
- async function migrateLegacyUser(userId: string) {
205
- configureMigration({
206
- from: 'old_users_collection',
207
- to: 'users',
208
- transform: (old) => ({
209
- displayName: old.full_name,
210
- email: old.email_addr,
211
- photoURL: old.profile_pic,
212
- createdAt: old.created_at,
213
- metadata: {
214
- migratedFrom: 'legacy',
215
- migratedAt: Date.now(),
216
- },
217
- }),
218
- });
219
-
220
- try {
221
- await migrateUserData(userId);
222
- console.log('Migration successful');
223
- } catch (error) {
224
- console.error('Migration failed:', error);
225
- }
226
- }
241
+ import {
242
+ migrateUserData,
243
+ configureMigration
244
+ } from '@umituz/react-native-auth';
227
245
  ```
228
246
 
229
- ## Type Guards
247
+ **FUNCTIONS**:
248
+ - `configureMigration(config)` - Configure migration
249
+ - `migrateUserData(userId)` - Run migration
230
250
 
231
- Domain type'ları için guard'lar:
251
+ **CONFIGURATION**:
252
+ - `from` - Source collection name
253
+ - `to` - Target collection name
254
+ - `transform` - Data transformation function
255
+ - `verify` - Verification function (optional)
232
256
 
233
- ```typescript
234
- function isAuthenticatedUser(user: AuthUser | null): user is AuthUser {
235
- return user !== null && !user.isAnonymous;
236
- }
257
+ **Rules**:
258
+ - MUST configure before migrating
259
+ - MUST transform data correctly
260
+ - MUST handle migration errors
261
+ - MUST verify migration success
262
+ - MUST not delete source automatically
237
263
 
238
- function isEmailVerified(user: AuthUser): boolean {
239
- return !!user.emailVerified;
240
- }
264
+ **MUST NOT**:
265
+ - Skip configuration
266
+ - Lose data during migration
267
+ - Assume identical schemas
268
+ - Delete source without verification
241
269
 
242
- function hasProvider(user: AuthUser, provider: string): boolean {
243
- return user.provider === provider;
244
- }
245
- ```
270
+ ---
271
+
272
+ ## Type Guards
246
273
 
247
- ## Domain Services
274
+ ### User Type Guards
248
275
 
249
- ### User Validation
276
+ **PURPOSE**: Type-safe user checking
250
277
 
278
+ **IMPORT PATH**:
251
279
  ```typescript
252
- function validateUserForRegistration(user: Partial<AuthUser>): ValidationResult {
253
- const errors: string[] = [];
254
-
255
- if (!user.email) {
256
- errors.push('Email is required');
257
- }
258
-
259
- if (!user.displayName || user.displayName.length < 2) {
260
- errors.push('Display name must be at least 2 characters');
261
- }
262
-
263
- return {
264
- isValid: errors.length === 0,
265
- errors,
266
- };
267
- }
280
+ import {
281
+ isAuthenticatedUser,
282
+ isAnonymousUser,
283
+ hasEmail
284
+ } from '@umituz/react-native-auth';
268
285
  ```
269
286
 
287
+ **GUARDS**:
288
+ - `isAuthenticatedUser(user)` - Check if authenticated user
289
+ - `isAnonymousUser(user)` - Check if anonymous user
290
+ - `hasEmail(user)` - Check if has email
291
+
292
+ **Rules**:
293
+ - MUST use for type narrowing
294
+ - MUST validate before operations
295
+ - MUST check null cases
296
+ - MUST return boolean
297
+
298
+ **MUST NOT**:
299
+ - Skip type guards
300
+ - Assume user type
301
+ - Skip null checks
302
+ - Return non-boolean
303
+
304
+ ---
305
+
270
306
  ## Domain Rules
271
307
 
272
- 1. **AuthUser Rules:**
273
- - Her kullanıcının unique bir `uid`'si olmalı
274
- - Anonymous kullanıcıların `email`'i yoktur
275
- - Social login kullanıcıları provider bilgisi taşır
308
+ ### AuthUser Rules
309
+
310
+ **MUST**:
311
+ - Have unique uid
312
+ - Validate uid not empty
313
+ - Validate email format if provided
314
+ - Check provider is valid
315
+ - Verify required fields
316
+
317
+ **MUST NOT**:
318
+ - Allow empty uid
319
+ - Accept invalid email
320
+ - Use wrong provider type
321
+ - Have anonymous user with email
322
+
323
+ **Constraints**:
324
+ - uid required
325
+ - Email format validated
326
+ - Provider must be known type
327
+ - Anonymous users have null email
328
+
329
+ ---
330
+
331
+ ### UserProfile Rules
332
+
333
+ **MUST**:
334
+ - Validate display name 2-50 characters
335
+ - Validate photo URL format
336
+ - Use server timestamps
337
+ - Handle partial updates
338
+ - Preserve existing data
339
+
340
+ **MUST NOT**:
341
+ - Allow display name < 2 chars
342
+ - Accept invalid URLs
343
+ - Use client timestamps
344
+ - Overwrite existing data
345
+
346
+ **Constraints**:
347
+ - Display name min 2, max 100 chars
348
+ - Cannot be only whitespace
349
+ - Valid URL required for photoURL
350
+ - One profile per uid
351
+
352
+ ---
353
+
354
+ ### Password Rules
355
+
356
+ **MUST**:
357
+ - Enforce minimum length
358
+ - Check uppercase if required
359
+ - Check lowercase if required
360
+ - Check number if required
361
+ - Check special char if required
362
+
363
+ **MUST NOT**:
364
+ - Allow weak passwords
365
+ - Skip validation checks
366
+ - Accept passwords below minimum
367
+
368
+ **Constraints**:
369
+ - Minimum length: 4-128 chars
370
+ - Requirements configurable
371
+ - All requirements optional
372
+ - Default min length: 6 (lenient)
373
+
374
+ ---
375
+
376
+ ## Best Practices
377
+
378
+ ### Entity Usage
379
+
380
+ **MUST**:
381
+ - Use type guards for type narrowing
382
+ - Validate before operations
383
+ - Handle null values appropriately
384
+ - Follow domain rules
385
+ - Use proper error types
386
+
387
+ **MUST NOT**:
388
+ - Skip validation
389
+ - Assume required fields present
390
+ - Ignore null cases
391
+ - Use generic error types
392
+ - Break domain rules
393
+
394
+ ---
395
+
396
+ ### Error Handling
397
+
398
+ **MUST**:
399
+ - Use domain error types
400
+ - Map provider errors to domain
401
+ - Provide context
402
+ - Show user-friendly messages
403
+ - Preserve error information
404
+
405
+ **MUST NOT**:
406
+ - Throw provider errors
407
+ - Expose technical details
408
+ - Lose error context
409
+ - Show stack traces
410
+ - Reveal sensitive data
411
+
412
+ ---
413
+
414
+ ### Configuration
415
+
416
+ **MUST**:
417
+ - Validate configuration
418
+ - Use appropriate defaults
419
+ - Test with production config
420
+ - Not use dev config in production
421
+
422
+ **MUST NOT**:
423
+ - Skip validation
424
+ - Use invalid config
425
+ - Ignore environment differences
426
+ - Hardcode production values
427
+
428
+ ---
429
+
430
+ ## Related Modules
431
+
432
+ - **Application** (`../application/README.md`) - Ports and interfaces
433
+ - **Infrastructure** (`../infrastructure/README.md`) - Implementations
434
+ - **Presentation** (`../presentation/README.md`) - UI components
276
435
 
277
- 2. **UserProfile Rules:**
278
- - `displayName` en az 2 karakter olmalı
279
- - `email` geçerli formatta olmalı
280
- - `photoURL` geçerli URL olmalı
436
+ ---
281
437
 
282
- 3. **Password Rules:**
283
- - Minimum 8 karakter
284
- - En az 1 büyük harf
285
- - En az 1 küçük harf
286
- - En az 1 rakam
287
- - En az 1 özel karakter
438
+ ## Entity Documentation
288
439
 
289
- ## İlgili Modüller
440
+ ### Detailed Entity Docs
290
441
 
291
- - **[Application](../application/README.md)** - Application ports
292
- - **[Infrastructure](../infrastructure/README.md)** - Infrastructure implementation
293
- - **[Presentation](../presentation/README.md)** - UI components ve hooks
442
+ **AuthUser**: `entities/AuthUser.md`
443
+ **UserProfile**: `entities/UserProfile.md`
444
+ **AuthConfig & AuthError**: `ConfigAndErrors.md`