@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.
- package/README.md +347 -348
- package/package.json +2 -3
- package/src/application/README.md +323 -442
- package/src/domain/ConfigAndErrors.md +296 -431
- package/src/domain/README.md +361 -210
- package/src/domain/entities/AuthUser.md +231 -372
- package/src/domain/entities/UserProfile.md +271 -441
- package/src/index.ts +35 -0
- package/src/infrastructure/README.md +388 -444
- package/src/infrastructure/services/README.md +386 -312
- package/src/infrastructure/utils/validation/BaseValidators.ts +35 -0
- package/src/infrastructure/utils/validation/CollectionValidators.ts +56 -0
- package/src/infrastructure/utils/validation/DateValidators.ts +63 -0
- package/src/infrastructure/utils/validation/FormValidators.ts +22 -0
- package/src/infrastructure/utils/validation/NumberValidators.ts +55 -0
- package/src/infrastructure/utils/validation/StringValidators.ts +55 -0
- package/src/infrastructure/utils/validation/sanitization.ts +98 -0
- package/src/infrastructure/utils/validation/types.ts +15 -0
- package/src/presentation/README.md +631 -563
- package/src/presentation/components/ProfileComponents.md +307 -504
- package/src/presentation/components/README.md +254 -92
- package/src/presentation/hooks/README.md +247 -83
- package/src/presentation/hooks/useAccountManagement.md +295 -344
- package/src/presentation/hooks/useAuth.md +271 -227
- package/src/presentation/hooks/useAuthBottomSheet.md +417 -367
- package/src/presentation/hooks/useAuthRequired.md +308 -194
- package/src/presentation/hooks/useProfileUpdate.md +251 -279
- package/src/presentation/hooks/useSocialLogin.md +312 -287
- package/src/presentation/hooks/useUserProfile.md +259 -192
- package/src/presentation/screens/README.md +151 -153
|
@@ -1,417 +1,491 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Infrastructure Services
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Core authentication services and infrastructure implementations.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Strategy
|
|
8
|
+
|
|
9
|
+
**Purpose**: Provides concrete implementations for authentication operations, user document management, event handling, and validation.
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
11
|
+
**When to Use**:
|
|
12
|
+
- Understanding service architecture
|
|
13
|
+
- Implementing custom services
|
|
14
|
+
- Debugging service issues
|
|
15
|
+
- Learning about Firebase integration
|
|
16
|
+
|
|
17
|
+
**Location**: `src/infrastructure/services/`
|
|
12
18
|
|
|
13
19
|
---
|
|
14
20
|
|
|
15
|
-
##
|
|
21
|
+
## Available Services
|
|
16
22
|
|
|
17
|
-
|
|
23
|
+
### AuthService
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
**PURPOSE**: Main authentication service orchestrating all auth operations
|
|
20
26
|
|
|
27
|
+
**IMPORT PATH**:
|
|
21
28
|
```typescript
|
|
22
29
|
import {
|
|
23
30
|
AuthService,
|
|
24
31
|
initializeAuthService,
|
|
25
|
-
getAuthService
|
|
32
|
+
getAuthService,
|
|
33
|
+
resetAuthService
|
|
26
34
|
} from '@umituz/react-native-auth';
|
|
35
|
+
```
|
|
27
36
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
**File**: `AuthService.ts`
|
|
38
|
+
|
|
39
|
+
**METHODS**:
|
|
40
|
+
- `signIn(params)` - Sign in with email/password
|
|
41
|
+
- `signUp(params)` - Create new account
|
|
42
|
+
- `signOut()` - Sign out current user
|
|
43
|
+
- `getCurrentUser()` - Get current user
|
|
44
|
+
- `sendPasswordResetEmail(email)` - Reset password
|
|
45
|
+
|
|
46
|
+
**FUNCTIONS**:
|
|
47
|
+
- `initializeAuthService(config)` - Initialize service
|
|
48
|
+
- `getAuthService()` - Get service instance
|
|
49
|
+
- `resetAuthService()` - Reset service (testing only)
|
|
50
|
+
|
|
51
|
+
**Rules**:
|
|
52
|
+
- MUST initialize before use
|
|
53
|
+
- MUST implement IAuthService interface
|
|
54
|
+
- MUST handle Firebase errors
|
|
55
|
+
- MUST create user documents on registration
|
|
56
|
+
- MUST not create multiple instances
|
|
57
|
+
|
|
58
|
+
**MUST NOT**:
|
|
59
|
+
- Skip initialization
|
|
60
|
+
- Use before initialization
|
|
61
|
+
- Expose Firebase types
|
|
62
|
+
- Create multiple service instances
|
|
63
|
+
- Skip error handling
|
|
32
64
|
|
|
33
|
-
|
|
34
|
-
const authService = getAuthService();
|
|
65
|
+
---
|
|
35
66
|
|
|
36
|
-
|
|
37
|
-
await authService.signIn({ email, password });
|
|
67
|
+
### initializeAuth
|
|
38
68
|
|
|
39
|
-
|
|
40
|
-
await authService.signUp({ email, password, displayName });
|
|
69
|
+
**PURPOSE**: Initialize authentication system and Firebase Auth state listener
|
|
41
70
|
|
|
42
|
-
|
|
43
|
-
|
|
71
|
+
**IMPORT PATH**:
|
|
72
|
+
```typescript
|
|
73
|
+
import {
|
|
74
|
+
initializeAuth,
|
|
75
|
+
isAuthInitialized,
|
|
76
|
+
resetAuthInitialization
|
|
77
|
+
} from '@umituz/react-native-auth';
|
|
44
78
|
```
|
|
45
79
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
#### Methods
|
|
49
|
-
|
|
50
|
-
| Method | Parametreler | Açıklama |
|
|
51
|
-
|--------|--------------|----------|
|
|
52
|
-
| `signIn` | `{ email, password }` | Email/password ile giriş |
|
|
53
|
-
| `signUp` | `{ email, password, displayName? }` | Yeni kullanıcı kaydı |
|
|
54
|
-
| `signOut` | - | Çıkış yapma |
|
|
55
|
-
| `sendPasswordResetEmail` | `email` | Şifre sıfırlama email'i gönderme |
|
|
80
|
+
**File**: `initializeAuth.ts`
|
|
56
81
|
|
|
57
|
-
|
|
82
|
+
**PARAMETERS**:
|
|
83
|
+
- `onAuthStateChanged` - Auth state callback (optional)
|
|
84
|
+
- `onAuthError` - Error callback (optional)
|
|
58
85
|
|
|
59
|
-
|
|
86
|
+
**FUNCTIONS**:
|
|
87
|
+
- `initializeAuth(options)` - Initialize auth system
|
|
88
|
+
- `isAuthInitialized()` - Check initialization status
|
|
89
|
+
- `resetAuthInitialization()` - Reset (testing only)
|
|
60
90
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const firebaseAuth = getAuth();
|
|
68
|
-
|
|
69
|
-
initializeAuthService({
|
|
70
|
-
firebaseAuth,
|
|
71
|
-
onAuthStateChanged: (user) => {
|
|
72
|
-
console.log('Auth state changed:', user);
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
}, []);
|
|
76
|
-
|
|
77
|
-
return <AppNavigator />;
|
|
78
|
-
}
|
|
79
|
-
```
|
|
91
|
+
**Rules**:
|
|
92
|
+
- MUST call once at app startup
|
|
93
|
+
- MUST wait for initialization completion
|
|
94
|
+
- MUST handle initialization errors
|
|
95
|
+
- MUST not call multiple times
|
|
96
|
+
- MUST check status before operations
|
|
80
97
|
|
|
81
|
-
|
|
98
|
+
**MUST NOT**:
|
|
99
|
+
- Skip initialization
|
|
100
|
+
- Call in components (use app root)
|
|
101
|
+
- Initialize multiple times
|
|
102
|
+
- Skip status check
|
|
103
|
+
- Ignore initialization errors
|
|
82
104
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
class CustomAuthService extends AuthService {
|
|
87
|
-
async signInWithCustomToken(token: string) {
|
|
88
|
-
// Custom implementation
|
|
89
|
-
const userCredential = await signInWithCustomToken(
|
|
90
|
-
this.firebaseAuth,
|
|
91
|
-
token
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
await this.ensureUserDocument(userCredential.user);
|
|
95
|
-
return userCredential.user;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Custom service kullanımı
|
|
100
|
-
const customService = new CustomAuthService({
|
|
101
|
-
firebaseAuth: getAuth(),
|
|
102
|
-
});
|
|
103
|
-
```
|
|
105
|
+
**CALLBACKS**:
|
|
106
|
+
- `onAuthStateChanged(user)` - Called when auth state changes
|
|
107
|
+
- `onAuthError(error)` - Called on auth errors
|
|
104
108
|
|
|
105
109
|
---
|
|
106
110
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
Authentication sistemini başlatır. Firebase Auth listener'ını kurar ve user state'ini yönetir.
|
|
111
|
+
### UserDocumentService
|
|
110
112
|
|
|
111
|
-
|
|
113
|
+
**PURPOSE**: Manage Firestore user documents
|
|
112
114
|
|
|
115
|
+
**IMPORT PATH**:
|
|
113
116
|
```typescript
|
|
114
|
-
import {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
await initializeAuth({
|
|
120
|
-
onAuthStateChanged: (user) => {
|
|
121
|
-
console.log('User:', user);
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
init();
|
|
127
|
-
}, []);
|
|
128
|
-
|
|
129
|
-
return <AppNavigator />;
|
|
130
|
-
}
|
|
117
|
+
import {
|
|
118
|
+
ensureUserDocument,
|
|
119
|
+
markUserDeleted,
|
|
120
|
+
configureUserDocumentService
|
|
121
|
+
} from '@umituz/react-native-auth';
|
|
131
122
|
```
|
|
132
123
|
|
|
133
|
-
|
|
124
|
+
**File**: `UserDocumentService.ts`
|
|
125
|
+
|
|
126
|
+
**FUNCTIONS**:
|
|
127
|
+
- `ensureUserDocument(user, data?)` - Create/retrieve user document
|
|
128
|
+
- `markUserDeleted(userId)` - Mark user as deleted
|
|
129
|
+
- `configureUserDocumentService(config)` - Configure service
|
|
130
|
+
|
|
131
|
+
**Rules**:
|
|
132
|
+
- MUST create document on registration
|
|
133
|
+
- MUST check document existence
|
|
134
|
+
- MUST use server timestamps
|
|
135
|
+
- MUST support custom configuration
|
|
136
|
+
- MUST not delete documents permanently
|
|
137
|
+
|
|
138
|
+
**MUST NOT**:
|
|
139
|
+
- Skip document creation
|
|
140
|
+
- Overwrite existing data
|
|
141
|
+
- Use client timestamps
|
|
142
|
+
- Hardcode collection name
|
|
143
|
+
- Delete documents permanently
|
|
144
|
+
|
|
145
|
+
**CONFIGURATION**:
|
|
146
|
+
- `collection` - Firestore collection name (default: 'users')
|
|
147
|
+
- `timestamps` - Add createdAt/updatedAt fields
|
|
148
|
+
- `userData` - Custom fields to add to documents
|
|
149
|
+
|
|
150
|
+
**CUSTOM DATA**:
|
|
151
|
+
- Can add custom fields on document creation
|
|
152
|
+
- Merges with existing data
|
|
153
|
+
- Supports nested objects
|
|
154
|
+
- Preserves user-provided data
|
|
134
155
|
|
|
135
|
-
|
|
136
|
-
interface InitializeAuthOptions {
|
|
137
|
-
onAuthStateChanged?: (user: AuthUser | null) => void;
|
|
138
|
-
onAuthError?: (error: Error) => void;
|
|
139
|
-
}
|
|
140
|
-
```
|
|
156
|
+
---
|
|
141
157
|
|
|
142
|
-
###
|
|
158
|
+
### AnonymousModeService
|
|
143
159
|
|
|
144
|
-
|
|
160
|
+
**PURPOSE**: Handle anonymous user authentication and upgrade
|
|
145
161
|
|
|
162
|
+
**IMPORT PATH**:
|
|
146
163
|
```typescript
|
|
147
|
-
import {
|
|
148
|
-
|
|
149
|
-
function App() {
|
|
150
|
-
useEffect(() => {
|
|
151
|
-
initializeAuth();
|
|
152
|
-
}, []);
|
|
153
|
-
|
|
154
|
-
return <Navigator />;
|
|
155
|
-
}
|
|
164
|
+
import { AnonymousModeService } from '@umituz/react-native-auth';
|
|
156
165
|
```
|
|
157
166
|
|
|
158
|
-
|
|
167
|
+
**File**: `AnonymousModeService.ts`
|
|
159
168
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
function App() {
|
|
164
|
-
const navigation = useNavigation();
|
|
165
|
-
|
|
166
|
-
useEffect(() => {
|
|
167
|
-
initializeAuth({
|
|
168
|
-
onAuthStateChanged: (user) => {
|
|
169
|
-
if (user) {
|
|
170
|
-
navigation.reset({
|
|
171
|
-
index: 0,
|
|
172
|
-
routes: [{ name: 'Home' }],
|
|
173
|
-
});
|
|
174
|
-
} else {
|
|
175
|
-
navigation.reset({
|
|
176
|
-
index: 0,
|
|
177
|
-
routes: [{ name: 'Login' }],
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
onAuthError: (error) => {
|
|
182
|
-
console.error('Auth error:', error);
|
|
183
|
-
Alert.alert('Auth Hatası', error.message);
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
}, []);
|
|
187
|
-
|
|
188
|
-
return <Navigator />;
|
|
189
|
-
}
|
|
190
|
-
```
|
|
169
|
+
**METHODS**:
|
|
170
|
+
- `signInAnonymously()` - Create anonymous user
|
|
191
171
|
|
|
192
|
-
|
|
172
|
+
**UPGRADE**:
|
|
173
|
+
- Handled via Firebase credential linking
|
|
174
|
+
- Converts anonymous to permanent account
|
|
175
|
+
- Preserves anonymous user data
|
|
193
176
|
|
|
194
|
-
|
|
177
|
+
**Rules**:
|
|
178
|
+
- MUST create temporary accounts
|
|
179
|
+
- MUST support upgrade to permanent account
|
|
180
|
+
- MUST warn about data loss
|
|
181
|
+
- MUST handle upgrade failures
|
|
182
|
+
- MUST not delete anonymous data on sign out
|
|
195
183
|
|
|
196
|
-
|
|
184
|
+
**MUST NOT**:
|
|
185
|
+
- Skip upgrade warnings
|
|
186
|
+
- Lose user data during upgrade
|
|
187
|
+
- Allow restricted operations without warning
|
|
188
|
+
- Make anonymous accounts permanent
|
|
197
189
|
|
|
198
|
-
|
|
190
|
+
**CONSTRAINTS**:
|
|
191
|
+
- Anonymous users have limited functionality
|
|
192
|
+
- Data lost if signed out without upgrade
|
|
193
|
+
- Upgrade requires valid credentials
|
|
194
|
+
- Cannot revert to anonymous after upgrade
|
|
199
195
|
|
|
200
|
-
|
|
201
|
-
import {
|
|
202
|
-
ensureUserDocument,
|
|
203
|
-
markUserDeleted,
|
|
204
|
-
configureUserDocumentService
|
|
205
|
-
} from '@umituz/react-native-auth';
|
|
196
|
+
---
|
|
206
197
|
|
|
207
|
-
|
|
208
|
-
await ensureUserDocument(user);
|
|
198
|
+
### AuthEventService
|
|
209
199
|
|
|
210
|
-
|
|
211
|
-
await markUserDeleted(user.uid);
|
|
200
|
+
**PURPOSE**: Pub/sub system for authentication events
|
|
212
201
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
timestamps: true,
|
|
217
|
-
});
|
|
202
|
+
**IMPORT PATH**:
|
|
203
|
+
```typescript
|
|
204
|
+
import { AuthEventService } from '@umituz/react-native-auth';
|
|
218
205
|
```
|
|
219
206
|
|
|
220
|
-
|
|
207
|
+
**File**: `AuthEventService.ts`
|
|
208
|
+
|
|
209
|
+
**METHODS**:
|
|
210
|
+
- `on(event, callback)` - Subscribe to event
|
|
211
|
+
- `emit(event, data)` - Emit event
|
|
212
|
+
- Returns unsubscribe function
|
|
213
|
+
|
|
214
|
+
**EVENTS**:
|
|
215
|
+
- `signIn` - User signed in (payload: AuthUser)
|
|
216
|
+
- `signUp` - New user registered (payload: AuthUser)
|
|
217
|
+
- `signOut` - User signed out (payload: undefined)
|
|
218
|
+
- `authStateChanged` - Auth state changed (payload: AuthUser | null)
|
|
219
|
+
|
|
220
|
+
**Rules**:
|
|
221
|
+
- MUST emit events on state changes
|
|
222
|
+
- MUST support multiple subscribers
|
|
223
|
+
- MUST provide unsubscribe function
|
|
224
|
+
- MUST not throw in event handlers
|
|
225
|
+
- MUST handle subscriber errors gracefully
|
|
226
|
+
|
|
227
|
+
**MUST NOT**:
|
|
228
|
+
- Skip critical events
|
|
229
|
+
- Block event emission on handler errors
|
|
230
|
+
- Throw unhandled errors
|
|
231
|
+
- Memory leak subscribers
|
|
232
|
+
- Modify event payload
|
|
233
|
+
|
|
234
|
+
**USAGE**:
|
|
235
|
+
- Subscribe returns unsubscribe function
|
|
236
|
+
- Multiple subscribers per event allowed
|
|
237
|
+
- Subscriber errors should not affect other subscribers
|
|
238
|
+
- Unsubscribe when done to prevent memory leaks
|
|
221
239
|
|
|
222
|
-
|
|
223
|
-
|--------|--------------|----------|
|
|
224
|
-
| `ensureUserDocument` | `user` | Kullanıcı dokümanını oluştur |
|
|
225
|
-
| `markUserDeleted` | `userId` | Kullanıcıyı silinmiş olarak işaretle |
|
|
226
|
-
| `configureUserDocumentService` | `config` | Service konfigürasyonu |
|
|
240
|
+
---
|
|
227
241
|
|
|
228
|
-
|
|
242
|
+
## Storage Adapter
|
|
229
243
|
|
|
230
|
-
|
|
244
|
+
### StorageProviderAdapter
|
|
231
245
|
|
|
232
|
-
|
|
233
|
-
import { configureUserDocumentService } from '@umituz/react-native-auth';
|
|
234
|
-
|
|
235
|
-
configureUserDocumentService({
|
|
236
|
-
collection: 'customers', // Varsayılan: 'users'
|
|
237
|
-
timestamps: true, // createdAt, updatedAt alanları ekle
|
|
238
|
-
userData: {
|
|
239
|
-
source: 'app',
|
|
240
|
-
version: '1.0.0',
|
|
241
|
-
},
|
|
242
|
-
});
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
#### Custom User Data
|
|
246
|
+
**PURPOSE**: Interface for storage providers (AsyncStorage, MMKV, etc.)
|
|
246
247
|
|
|
248
|
+
**IMPORT PATH**:
|
|
247
249
|
```typescript
|
|
248
|
-
import {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
await ensureUserDocument(user, {
|
|
253
|
-
role: 'user',
|
|
254
|
-
subscription: 'free',
|
|
255
|
-
preferences: {
|
|
256
|
-
newsletter: true,
|
|
257
|
-
notifications: true,
|
|
258
|
-
},
|
|
259
|
-
});
|
|
250
|
+
import {
|
|
251
|
+
createStorageProvider,
|
|
252
|
+
StorageProviderAdapter
|
|
253
|
+
} from '@umituz/react-native-auth';
|
|
260
254
|
```
|
|
261
255
|
|
|
256
|
+
**INTERFACE METHODS**:
|
|
257
|
+
- `getItem(key)` - Retrieve value (returns string | null)
|
|
258
|
+
- `setItem(key, value)` - Store value
|
|
259
|
+
- `removeItem(key)` - Delete value
|
|
260
|
+
|
|
261
|
+
**Rules**:
|
|
262
|
+
- MUST implement all three methods
|
|
263
|
+
- MUST handle async operations
|
|
264
|
+
- MUST return null for missing keys
|
|
265
|
+
- MUST handle storage errors
|
|
266
|
+
- MUST only store string values
|
|
267
|
+
|
|
268
|
+
**MUST NOT**:
|
|
269
|
+
- Throw for missing keys
|
|
270
|
+
- Skip error handling
|
|
271
|
+
- Assume synchronous operations
|
|
272
|
+
- Store non-string values
|
|
273
|
+
- Return undefined for missing keys
|
|
274
|
+
|
|
275
|
+
**IMPLEMENTATIONS**:
|
|
276
|
+
- AsyncStorage (React Native default)
|
|
277
|
+
- MMKV (faster alternative)
|
|
278
|
+
- SecureStorage (for sensitive data)
|
|
279
|
+
- Custom implementations allowed
|
|
280
|
+
|
|
262
281
|
---
|
|
263
282
|
|
|
264
|
-
##
|
|
283
|
+
## Validation
|
|
265
284
|
|
|
266
|
-
|
|
285
|
+
### AuthValidation Utilities
|
|
267
286
|
|
|
268
|
-
|
|
287
|
+
**PURPOSE**: Input validation for authentication forms
|
|
269
288
|
|
|
289
|
+
**IMPORT PATH**:
|
|
270
290
|
```typescript
|
|
271
|
-
import {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const credential = EmailAuthProvider.credential(email, password);
|
|
280
|
-
await user.linkWithCredential(credential);
|
|
291
|
+
import {
|
|
292
|
+
validateEmail,
|
|
293
|
+
validatePasswordForLogin,
|
|
294
|
+
validatePasswordForRegister,
|
|
295
|
+
validatePasswordConfirmation,
|
|
296
|
+
validateDisplayName,
|
|
297
|
+
DEFAULT_VAL_CONFIG
|
|
298
|
+
} from '@umituz/react-native-auth';
|
|
281
299
|
```
|
|
282
300
|
|
|
301
|
+
**VALIDATORS**:
|
|
302
|
+
|
|
303
|
+
**validateEmail(email)**
|
|
304
|
+
- Validates email format
|
|
305
|
+
- Returns: `{ isValid: boolean, error?: string }`
|
|
306
|
+
|
|
307
|
+
**validatePasswordForLogin(password)**
|
|
308
|
+
- Checks password not empty
|
|
309
|
+
- Returns: `{ isValid: boolean, error?: string }`
|
|
310
|
+
|
|
311
|
+
**validatePasswordForRegister(password)**
|
|
312
|
+
- Checks password complexity
|
|
313
|
+
- Returns: `{ isValid: boolean, error?: string, requirements: PasswordRequirements }`
|
|
314
|
+
|
|
315
|
+
**validatePasswordConfirmation(password, confirmation)**
|
|
316
|
+
- Checks passwords match
|
|
317
|
+
- Returns: `{ isValid: boolean, matches: boolean, error?: string }`
|
|
318
|
+
|
|
319
|
+
**validateDisplayName(name)**
|
|
320
|
+
- Validates display name
|
|
321
|
+
- Returns: `{ isValid: boolean, error?: string }`
|
|
322
|
+
|
|
323
|
+
**Rules**:
|
|
324
|
+
- MUST return validation result object
|
|
325
|
+
- MUST provide error messages
|
|
326
|
+
- MUST use configurable rules
|
|
327
|
+
- MUST not throw for invalid input
|
|
328
|
+
- MUST support internationalization
|
|
329
|
+
|
|
330
|
+
**MUST NOT**:
|
|
331
|
+
- Return boolean only
|
|
332
|
+
- Skip error messages
|
|
333
|
+
- Hardcode validation rules
|
|
334
|
+
- Throw on validation failure
|
|
335
|
+
- Assume required fields present
|
|
336
|
+
|
|
337
|
+
**DEFAULT CONFIG**:
|
|
338
|
+
- `password.minLength` - 8 characters
|
|
339
|
+
- `password.requireUppercase` - true
|
|
340
|
+
- `password.requireLowercase` - true
|
|
341
|
+
- `password.requireNumber` - true
|
|
342
|
+
- `password.requireSpecialChar` - true
|
|
343
|
+
|
|
283
344
|
---
|
|
284
345
|
|
|
285
|
-
##
|
|
346
|
+
## Migration Utilities
|
|
286
347
|
|
|
287
|
-
|
|
348
|
+
### User Data Migration
|
|
288
349
|
|
|
289
|
-
|
|
350
|
+
**PURPOSE**: Migrate user data between collections
|
|
290
351
|
|
|
352
|
+
**IMPORT PATH**:
|
|
291
353
|
```typescript
|
|
292
|
-
import {
|
|
354
|
+
import {
|
|
355
|
+
migrateUserData,
|
|
356
|
+
configureMigration
|
|
357
|
+
} from '@umituz/react-native-auth';
|
|
358
|
+
```
|
|
293
359
|
|
|
294
|
-
|
|
360
|
+
**FUNCTIONS**:
|
|
361
|
+
- `configureMigration(config)` - Configure migration
|
|
362
|
+
- `migrateUserData(userId)` - Run migration
|
|
363
|
+
|
|
364
|
+
**Rules**:
|
|
365
|
+
- MUST configure before migrating
|
|
366
|
+
- MUST transform data correctly
|
|
367
|
+
- MUST handle migration errors
|
|
368
|
+
- MUST verify migration success
|
|
369
|
+
- MUST not delete source data automatically
|
|
370
|
+
|
|
371
|
+
**MUST NOT**:
|
|
372
|
+
- Skip configuration
|
|
373
|
+
- Lose data during migration
|
|
374
|
+
- Assume identical schemas
|
|
375
|
+
- Delete source without verification
|
|
376
|
+
- Migrate without backup
|
|
377
|
+
|
|
378
|
+
**CONFIGURATION**:
|
|
379
|
+
- `from` - Source collection name
|
|
380
|
+
- `to` - Target collection name
|
|
381
|
+
- `transform` - Data transformation function
|
|
382
|
+
- `verify` - Verification function (optional)
|
|
295
383
|
|
|
296
|
-
|
|
297
|
-
const unsubscribe = eventService.on('signIn', (user) => {
|
|
298
|
-
console.log('User signed in:', user);
|
|
299
|
-
});
|
|
384
|
+
---
|
|
300
385
|
|
|
301
|
-
|
|
302
|
-
eventService.emit('signIn', user);
|
|
386
|
+
## Best Practices
|
|
303
387
|
|
|
304
|
-
|
|
305
|
-
unsubscribe();
|
|
306
|
-
```
|
|
388
|
+
### Service Initialization
|
|
307
389
|
|
|
308
|
-
|
|
390
|
+
**MUST**:
|
|
391
|
+
- Initialize services at app root
|
|
392
|
+
- Wait for initialization completion
|
|
393
|
+
- Handle initialization errors
|
|
394
|
+
- Check initialization status
|
|
395
|
+
- Configure before initialization
|
|
309
396
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
397
|
+
**MUST NOT**:
|
|
398
|
+
- Initialize in components
|
|
399
|
+
- Use before initialization
|
|
400
|
+
- Skip error handling
|
|
401
|
+
- Initialize multiple times
|
|
402
|
+
- Ignore status checks
|
|
316
403
|
|
|
317
404
|
---
|
|
318
405
|
|
|
319
|
-
|
|
406
|
+
### User Document Management
|
|
320
407
|
|
|
321
|
-
|
|
408
|
+
**MUST**:
|
|
409
|
+
- Create documents on registration
|
|
410
|
+
- Use server timestamps
|
|
411
|
+
- Handle existing documents
|
|
412
|
+
- Configure collection name
|
|
413
|
+
- Add custom fields appropriately
|
|
322
414
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
to: 'users',
|
|
330
|
-
transform: (legacyData) => ({
|
|
331
|
-
displayName: legacyData.name,
|
|
332
|
-
email: legacyData.email_address,
|
|
333
|
-
createdAt: legacyData.joined_at,
|
|
334
|
-
}),
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
// Migration çalıştırma
|
|
338
|
-
await migrateUserData(userId);
|
|
339
|
-
```
|
|
415
|
+
**MUST NOT**:
|
|
416
|
+
- Skip document creation
|
|
417
|
+
- Overwrite existing data unnecessarily
|
|
418
|
+
- Use client timestamps
|
|
419
|
+
- Hardcode collection names
|
|
420
|
+
- Delete documents permanently
|
|
340
421
|
|
|
341
422
|
---
|
|
342
423
|
|
|
343
|
-
|
|
424
|
+
### Event Handling
|
|
344
425
|
|
|
345
|
-
|
|
426
|
+
**MUST**:
|
|
427
|
+
- Emit events on all state changes
|
|
428
|
+
- Support multiple subscribers
|
|
429
|
+
- Provide unsubscribe function
|
|
430
|
+
- Handle subscriber errors gracefully
|
|
431
|
+
- Unsubscribe when done
|
|
346
432
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
433
|
+
**MUST NOT**:
|
|
434
|
+
- Skip critical events
|
|
435
|
+
- Block on subscriber errors
|
|
436
|
+
- Throw unhandled errors
|
|
437
|
+
- Memory leak subscribers
|
|
438
|
+
- Emit duplicate events
|
|
352
439
|
|
|
353
|
-
|
|
354
|
-
class CustomStorageAdapter implements StorageProviderAdapter {
|
|
355
|
-
async getItem(key: string): Promise<string | null> {
|
|
356
|
-
return await AsyncStorage.getItem(key);
|
|
357
|
-
}
|
|
440
|
+
---
|
|
358
441
|
|
|
359
|
-
|
|
360
|
-
await AsyncStorage.setItem(key, value);
|
|
361
|
-
}
|
|
442
|
+
### Validation
|
|
362
443
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
444
|
+
**MUST**:
|
|
445
|
+
- Validate all user inputs
|
|
446
|
+
- Provide clear error messages
|
|
447
|
+
- Use consistent return types
|
|
448
|
+
- Support internationalization
|
|
449
|
+
- Configure rules appropriately
|
|
367
450
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
451
|
+
**MUST NOT**:
|
|
452
|
+
- Skip validation
|
|
453
|
+
- Return ambiguous results
|
|
454
|
+
- Hardcode rules
|
|
455
|
+
- Throw on invalid input
|
|
456
|
+
- Assume required fields present
|
|
371
457
|
|
|
372
458
|
---
|
|
373
459
|
|
|
374
|
-
##
|
|
460
|
+
## Error Handling
|
|
375
461
|
|
|
376
|
-
|
|
462
|
+
### Service Errors
|
|
377
463
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
validateDisplayName
|
|
385
|
-
} from '@umituz/react-native-auth';
|
|
386
|
-
|
|
387
|
-
// Email validasyonu
|
|
388
|
-
const emailResult = validateEmail('test@example.com');
|
|
389
|
-
// { isValid: true }
|
|
390
|
-
|
|
391
|
-
// Şifre validasyonu (kayıt için)
|
|
392
|
-
const passwordResult = validatePasswordForRegister('MyPass123!');
|
|
393
|
-
// {
|
|
394
|
-
// isValid: true,
|
|
395
|
-
// requirements: { hasMinLength: true, hasUppercase: true, ... }
|
|
396
|
-
// }
|
|
464
|
+
**STRATEGY**:
|
|
465
|
+
- Map Firebase errors to domain errors
|
|
466
|
+
- Provide error context
|
|
467
|
+
- Log appropriately
|
|
468
|
+
- Show user-friendly messages
|
|
469
|
+
- Allow retry where appropriate
|
|
397
470
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
471
|
+
**Rules**:
|
|
472
|
+
- MUST map all Firebase errors
|
|
473
|
+
- MUST preserve error context
|
|
474
|
+
- MUST use domain error types
|
|
475
|
+
- MUST handle network failures
|
|
476
|
+
- MUST not expose implementation details
|
|
401
477
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
// { isValid: true }
|
|
409
|
-
```
|
|
478
|
+
**MUST NOT**:
|
|
479
|
+
- Throw raw Firebase errors
|
|
480
|
+
- Lose error context
|
|
481
|
+
- Expose technical details
|
|
482
|
+
- Skip error logging
|
|
483
|
+
- Suppress errors silently
|
|
410
484
|
|
|
411
485
|
---
|
|
412
486
|
|
|
413
|
-
##
|
|
487
|
+
## Related Modules
|
|
414
488
|
|
|
415
|
-
- **
|
|
416
|
-
- **
|
|
417
|
-
- **
|
|
489
|
+
- **Domain** (`../../domain/README.md`) - AuthUser entity, AuthError, AuthConfig
|
|
490
|
+
- **Application** (`../../application/README.md`) - IAuthService, IAuthProvider interfaces
|
|
491
|
+
- **Presentation** (`../../presentation/README.md`) - UI components and hooks
|