@umituz/react-native-auth 3.4.30 → 3.4.32
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 +426 -0
- package/package.json +1 -3
- package/src/application/README.md +513 -0
- package/src/domain/ConfigAndErrors.md +545 -0
- package/src/domain/README.md +293 -0
- package/src/domain/entities/AuthUser.md +377 -0
- package/src/domain/entities/UserProfile.md +443 -0
- package/src/infrastructure/README.md +576 -0
- package/src/infrastructure/services/README.md +417 -0
- package/src/presentation/README.md +770 -0
- package/src/presentation/components/AuthBackground.tsx +21 -0
- package/src/presentation/components/AuthContainer.tsx +3 -3
- package/src/presentation/components/LoginForm.md +222 -0
- package/src/presentation/components/PasswordIndicators.md +260 -0
- package/src/presentation/components/ProfileComponents.md +575 -0
- package/src/presentation/components/README.md +117 -0
- package/src/presentation/components/SocialLoginButtons.md +340 -0
- package/src/presentation/hooks/README.md +122 -0
- package/src/presentation/hooks/useAccountManagement.md +386 -0
- package/src/presentation/hooks/useAuth.md +255 -0
- package/src/presentation/hooks/useAuthBottomSheet.md +414 -0
- package/src/presentation/hooks/useAuthRequired.md +248 -0
- package/src/presentation/hooks/useProfileUpdate.md +327 -0
- package/src/presentation/hooks/useSocialLogin.md +356 -0
- package/src/presentation/hooks/useUserProfile.md +230 -0
- package/src/presentation/screens/README.md +198 -0
- package/src/presentation/components/AuthGradientBackground.tsx +0 -33
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
# Auth Services
|
|
2
|
+
|
|
3
|
+
React Native Auth paketi için core servisler ve authentication işlevselliği.
|
|
4
|
+
|
|
5
|
+
## Servisler
|
|
6
|
+
|
|
7
|
+
- **[`AuthService`](./AuthService.ts)** - Ana authentication servisi
|
|
8
|
+
- **[`initializeAuth`](./initializeAuth.ts)** - Auth başlatma servisi
|
|
9
|
+
- **[`UserDocumentService`](./UserDocumentService.ts)** - Kullanıcı dokümanı servisi
|
|
10
|
+
- **[`AnonymousModeService`](./AnonymousModeService.ts)** - Anonymous mod servisi
|
|
11
|
+
- **[`AuthEventService`](./AuthEventService.ts)** - Auth event servisi
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## AuthService
|
|
16
|
+
|
|
17
|
+
Ana authentication servisi. Firebase Authentication ile tüm auth işlemlerini yönetir.
|
|
18
|
+
|
|
19
|
+
### Kullanım
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import {
|
|
23
|
+
AuthService,
|
|
24
|
+
initializeAuthService,
|
|
25
|
+
getAuthService
|
|
26
|
+
} from '@umituz/react-native-auth';
|
|
27
|
+
|
|
28
|
+
// Service başlatma
|
|
29
|
+
initializeAuthService({
|
|
30
|
+
firebaseAuth: getAuth(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Service alma
|
|
34
|
+
const authService = getAuthService();
|
|
35
|
+
|
|
36
|
+
// Giriş yapma
|
|
37
|
+
await authService.signIn({ email, password });
|
|
38
|
+
|
|
39
|
+
// Kayıt olma
|
|
40
|
+
await authService.signUp({ email, password, displayName });
|
|
41
|
+
|
|
42
|
+
// Çıkış yapma
|
|
43
|
+
await authService.signOut();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### API
|
|
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 |
|
|
56
|
+
|
|
57
|
+
### Örnekler
|
|
58
|
+
|
|
59
|
+
#### Service Başlatma
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { initializeAuthService } from '@umituz/react-native-auth';
|
|
63
|
+
import { getAuth } from 'firebase/auth';
|
|
64
|
+
|
|
65
|
+
function App() {
|
|
66
|
+
useEffect(() => {
|
|
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
|
+
```
|
|
80
|
+
|
|
81
|
+
#### Custom AuthService
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { AuthService } from '@umituz/react-native-auth';
|
|
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
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## initializeAuth
|
|
108
|
+
|
|
109
|
+
Authentication sistemini başlatır. Firebase Auth listener'ını kurar ve user state'ini yönetir.
|
|
110
|
+
|
|
111
|
+
### Kullanım
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { initializeAuth } from '@umituz/react-native-auth';
|
|
115
|
+
|
|
116
|
+
function App() {
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
const init = async () => {
|
|
119
|
+
await initializeAuth({
|
|
120
|
+
onAuthStateChanged: (user) => {
|
|
121
|
+
console.log('User:', user);
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
init();
|
|
127
|
+
}, []);
|
|
128
|
+
|
|
129
|
+
return <AppNavigator />;
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Options
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
interface InitializeAuthOptions {
|
|
137
|
+
onAuthStateChanged?: (user: AuthUser | null) => void;
|
|
138
|
+
onAuthError?: (error: Error) => void;
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Örnekler
|
|
143
|
+
|
|
144
|
+
#### Basit Başlatma
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { initializeAuth } from '@umituz/react-native-auth';
|
|
148
|
+
|
|
149
|
+
function App() {
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
initializeAuth();
|
|
152
|
+
}, []);
|
|
153
|
+
|
|
154
|
+
return <Navigator />;
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### Callback ile Başlatma
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { initializeAuth } from '@umituz/react-native-auth';
|
|
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
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## UserDocumentService
|
|
195
|
+
|
|
196
|
+
Firestore'da kullanıcı dokümanlarını yönetir.
|
|
197
|
+
|
|
198
|
+
### Kullanım
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import {
|
|
202
|
+
ensureUserDocument,
|
|
203
|
+
markUserDeleted,
|
|
204
|
+
configureUserDocumentService
|
|
205
|
+
} from '@umituz/react-native-auth';
|
|
206
|
+
|
|
207
|
+
// Kullanıcı dokümanını garanti altına al
|
|
208
|
+
await ensureUserDocument(user);
|
|
209
|
+
|
|
210
|
+
// Kullanıcıyı silinmiş olarak işaretle
|
|
211
|
+
await markUserDeleted(user.uid);
|
|
212
|
+
|
|
213
|
+
// Service konfigürasyonu
|
|
214
|
+
configureUserDocumentService({
|
|
215
|
+
collection: 'users',
|
|
216
|
+
timestamps: true,
|
|
217
|
+
});
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### API
|
|
221
|
+
|
|
222
|
+
| Method | Parametreler | Açıklama |
|
|
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 |
|
|
227
|
+
|
|
228
|
+
### Örnekler
|
|
229
|
+
|
|
230
|
+
#### Custom Konfigürasyon
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
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
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
import { ensureUserDocument } from '@umituz/react-native-auth';
|
|
249
|
+
|
|
250
|
+
const user = await signInWithGoogle();
|
|
251
|
+
|
|
252
|
+
await ensureUserDocument(user, {
|
|
253
|
+
role: 'user',
|
|
254
|
+
subscription: 'free',
|
|
255
|
+
preferences: {
|
|
256
|
+
newsletter: true,
|
|
257
|
+
notifications: true,
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## AnonymousModeService
|
|
265
|
+
|
|
266
|
+
Anonymous kullanıcı modunu yönetir.
|
|
267
|
+
|
|
268
|
+
### Kullanım
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import { AnonymousModeService } from '@umituz/react-native-auth';
|
|
272
|
+
|
|
273
|
+
const anonymousService = new AnonymousModeService();
|
|
274
|
+
|
|
275
|
+
// Anonymous kullanıcı oluştur
|
|
276
|
+
const user = await anonymousService.signInAnonymously();
|
|
277
|
+
|
|
278
|
+
// Anonymous kullanıcıyı authenticated kullanıcısına yükselt
|
|
279
|
+
const credential = EmailAuthProvider.credential(email, password);
|
|
280
|
+
await user.linkWithCredential(credential);
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## AuthEventService
|
|
286
|
+
|
|
287
|
+
Authentication event'lerini yönetir ve yayınlar.
|
|
288
|
+
|
|
289
|
+
### Kullanım
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
import { AuthEventService } from '@umituz/react-native-auth';
|
|
293
|
+
|
|
294
|
+
const eventService = new AuthEventService();
|
|
295
|
+
|
|
296
|
+
// Event dinle
|
|
297
|
+
const unsubscribe = eventService.on('signIn', (user) => {
|
|
298
|
+
console.log('User signed in:', user);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// Event tetikle
|
|
302
|
+
eventService.emit('signIn', user);
|
|
303
|
+
|
|
304
|
+
// Dinlemeyi bırak
|
|
305
|
+
unsubscribe();
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Event Türleri
|
|
309
|
+
|
|
310
|
+
| Event | Açıklama |
|
|
311
|
+
|-------|----------|
|
|
312
|
+
| `signIn` | Kullanıcı giriş yaptı |
|
|
313
|
+
| `signUp` | Yeni kullanıcı kayıt oldu |
|
|
314
|
+
| `signOut` | Kullanıcı çıkış yaptı |
|
|
315
|
+
| `authStateChanged` | Auth state değişti |
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## Migration
|
|
320
|
+
|
|
321
|
+
Kullanıcı verilerini taşımak için utility:
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
import { migrateUserData, configureMigration } from '@umituz/react-native-auth';
|
|
325
|
+
|
|
326
|
+
// Migration konfigürasyonu
|
|
327
|
+
configureMigration({
|
|
328
|
+
from: 'legacy_users',
|
|
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
|
+
```
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## Storage Provider
|
|
344
|
+
|
|
345
|
+
Custom storage provider tanımlama:
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
import {
|
|
349
|
+
createStorageProvider,
|
|
350
|
+
StorageProviderAdapter
|
|
351
|
+
} from '@umituz/react-native-auth';
|
|
352
|
+
|
|
353
|
+
// Custom storage provider
|
|
354
|
+
class CustomStorageAdapter implements StorageProviderAdapter {
|
|
355
|
+
async getItem(key: string): Promise<string | null> {
|
|
356
|
+
return await AsyncStorage.getItem(key);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
async setItem(key: string, value: string): Promise<void> {
|
|
360
|
+
await AsyncStorage.setItem(key, value);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
async removeItem(key: string): Promise<void> {
|
|
364
|
+
await AsyncStorage.removeItem(key);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Kullanımı
|
|
369
|
+
const storageProvider = createStorageProvider(new CustomStorageAdapter());
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
## Validation
|
|
375
|
+
|
|
376
|
+
Auth validasyon utility'leri:
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
import {
|
|
380
|
+
validateEmail,
|
|
381
|
+
validatePasswordForLogin,
|
|
382
|
+
validatePasswordForRegister,
|
|
383
|
+
validatePasswordConfirmation,
|
|
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
|
+
// }
|
|
397
|
+
|
|
398
|
+
// Şifre validasyonu (giriş için)
|
|
399
|
+
const loginPasswordResult = validatePasswordForLogin('password');
|
|
400
|
+
// { isValid: true }
|
|
401
|
+
|
|
402
|
+
// Şifre eşleşme validasyonu
|
|
403
|
+
const matchResult = validatePasswordConfirmation('password', 'password');
|
|
404
|
+
// { isValid: true, matches: true }
|
|
405
|
+
|
|
406
|
+
// DisplayName validasyonu
|
|
407
|
+
const nameResult = validateDisplayName('John Doe');
|
|
408
|
+
// { isValid: true }
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## İlgili Modüller
|
|
414
|
+
|
|
415
|
+
- **[Domain](../../domain/README.md)** - Domain entities ve value objects
|
|
416
|
+
- **[Application](../../application/README.md)** - Application ports ve interfaces
|
|
417
|
+
- **[Hooks](../../presentation/hooks/README.md)** - React hooks
|