@umituz/react-native-auth 3.4.31 → 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/package.json +1 -1
- package/src/presentation/README.md +2 -2
- package/src/presentation/components/LoginForm.md +158 -267
- package/src/presentation/components/PasswordIndicators.md +199 -410
- package/src/presentation/components/ProfileComponents.md +254 -111
- package/src/presentation/components/SocialLoginButtons.md +295 -258
- package/src/presentation/hooks/useAccountManagement.md +191 -185
- package/src/presentation/hooks/useAuthBottomSheet.md +74 -77
- package/src/presentation/hooks/useSocialLogin.md +90 -145
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# useAuthBottomSheet
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Hook for authentication bottom sheet management. Handles login/register modal display and social authentication.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
- Bottom sheet modal
|
|
8
|
-
- Login/Register
|
|
9
|
-
- Social authentication
|
|
10
|
-
-
|
|
11
|
-
- Pending callback
|
|
7
|
+
- Bottom sheet modal management
|
|
8
|
+
- Login/Register mode switching
|
|
9
|
+
- Social authentication integration
|
|
10
|
+
- Auto-close on successful auth
|
|
11
|
+
- Pending callback management
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Usage
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
16
|
import { useAuthBottomSheet } from '@umituz/react-native-auth';
|
|
@@ -67,13 +67,13 @@ function AuthBottomSheet() {
|
|
|
67
67
|
|
|
68
68
|
### Parameters
|
|
69
69
|
|
|
70
|
-
| Param |
|
|
71
|
-
|
|
72
|
-
| `socialConfig` | `SocialAuthConfiguration` | No | Social auth
|
|
70
|
+
| Param | Type | Required | Description |
|
|
71
|
+
|-------|------|----------|-------------|
|
|
72
|
+
| `socialConfig` | `SocialAuthConfiguration` | No | Social auth configuration |
|
|
73
73
|
| `onGoogleSignIn` | `() => Promise<void>` | No | Custom Google sign-in handler |
|
|
74
74
|
| `onAppleSignIn` | `() => Promise<void>` | No | Custom Apple sign-in handler |
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
### SocialAuthConfiguration
|
|
77
77
|
|
|
78
78
|
```typescript
|
|
79
79
|
interface SocialAuthConfiguration {
|
|
@@ -84,23 +84,23 @@ interface SocialAuthConfiguration {
|
|
|
84
84
|
|
|
85
85
|
### Return Value
|
|
86
86
|
|
|
87
|
-
| Prop |
|
|
88
|
-
|
|
89
|
-
| `modalRef` | `RefObject<BottomSheetModalRef>` | Bottom sheet modal
|
|
90
|
-
| `mode` | `'login' \| 'register'` |
|
|
91
|
-
| `providers` | `SocialAuthProvider[]` |
|
|
92
|
-
| `googleLoading` | `boolean` | Google loading
|
|
93
|
-
| `appleLoading` | `boolean` | Apple loading
|
|
94
|
-
| `handleDismiss` | `() => void` |
|
|
95
|
-
| `handleClose` | `() => void` |
|
|
96
|
-
| `handleNavigateToRegister` | `() => void` |
|
|
97
|
-
| `handleNavigateToLogin` | `() => void` |
|
|
98
|
-
| `handleGoogleSignIn` | `() => Promise<void>` | Google
|
|
99
|
-
| `handleAppleSignIn` | `() => Promise<void>` | Apple
|
|
87
|
+
| Prop | Type | Description |
|
|
88
|
+
|------|------|-------------|
|
|
89
|
+
| `modalRef` | `RefObject<BottomSheetModalRef>` | Bottom sheet modal reference |
|
|
90
|
+
| `mode` | `'login' \| 'register'` | Current mode |
|
|
91
|
+
| `providers` | `SocialAuthProvider[]` | Available social providers |
|
|
92
|
+
| `googleLoading` | `boolean` | Google loading state |
|
|
93
|
+
| `appleLoading` | `boolean` | Apple loading state |
|
|
94
|
+
| `handleDismiss` | `() => void` | Dismiss modal |
|
|
95
|
+
| `handleClose` | `() => void` | Close modal and cleanup |
|
|
96
|
+
| `handleNavigateToRegister` | `() => void` | Switch to register mode |
|
|
97
|
+
| `handleNavigateToLogin` | `() => void` | Switch to login mode |
|
|
98
|
+
| `handleGoogleSignIn` | `() => Promise<void>` | Google sign-in handler |
|
|
99
|
+
| `handleAppleSignIn` | `() => Promise<void>` | Apple sign-in handler |
|
|
100
100
|
|
|
101
|
-
##
|
|
101
|
+
## Examples
|
|
102
102
|
|
|
103
|
-
###
|
|
103
|
+
### Basic Auth Bottom Sheet
|
|
104
104
|
|
|
105
105
|
```typescript
|
|
106
106
|
function AuthModal() {
|
|
@@ -117,18 +117,18 @@ function AuthModal() {
|
|
|
117
117
|
<View>
|
|
118
118
|
{mode === 'login' ? (
|
|
119
119
|
<>
|
|
120
|
-
<Text>
|
|
120
|
+
<Text>Sign In</Text>
|
|
121
121
|
<LoginForm />
|
|
122
122
|
<Button onPress={handleNavigateToRegister}>
|
|
123
|
-
|
|
123
|
+
Don't have an account? Sign Up
|
|
124
124
|
</Button>
|
|
125
125
|
</>
|
|
126
126
|
) : (
|
|
127
127
|
<>
|
|
128
|
-
<Text>
|
|
128
|
+
<Text>Sign Up</Text>
|
|
129
129
|
<RegisterForm />
|
|
130
130
|
<Button onPress={handleNavigateToLogin}>
|
|
131
|
-
|
|
131
|
+
Already have an account? Sign In
|
|
132
132
|
</Button>
|
|
133
133
|
</>
|
|
134
134
|
)}
|
|
@@ -138,7 +138,7 @@ function AuthModal() {
|
|
|
138
138
|
}
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
### Social Login
|
|
141
|
+
### With Social Login
|
|
142
142
|
|
|
143
143
|
```typescript
|
|
144
144
|
function AuthBottomSheetWithSocial() {
|
|
@@ -188,7 +188,7 @@ function AuthBottomSheetWithSocial() {
|
|
|
188
188
|
)}
|
|
189
189
|
|
|
190
190
|
<Button onPress={handleNavigateToRegister}>
|
|
191
|
-
|
|
191
|
+
Sign Up
|
|
192
192
|
</Button>
|
|
193
193
|
</>
|
|
194
194
|
) : (
|
|
@@ -213,7 +213,7 @@ function AuthBottomSheetWithSocial() {
|
|
|
213
213
|
)}
|
|
214
214
|
|
|
215
215
|
<Button onPress={handleNavigateToLogin}>
|
|
216
|
-
|
|
216
|
+
Sign In
|
|
217
217
|
</Button>
|
|
218
218
|
</>
|
|
219
219
|
)}
|
|
@@ -231,28 +231,26 @@ function AuthBottomSheetWithCustomHandlers() {
|
|
|
231
231
|
|
|
232
232
|
const handleCustomGoogleSignIn = async () => {
|
|
233
233
|
try {
|
|
234
|
-
// Custom Google sign-in logic
|
|
235
234
|
const result = await customGoogleSignInFlow();
|
|
236
235
|
|
|
237
236
|
if (result.success) {
|
|
238
|
-
//
|
|
239
|
-
console.log('Google
|
|
237
|
+
// Modal auto-closes on successful auth
|
|
238
|
+
console.log('Google sign-in successful');
|
|
240
239
|
}
|
|
241
240
|
} catch (error) {
|
|
242
|
-
Alert.alert('
|
|
241
|
+
Alert.alert('Error', 'Google sign-in failed');
|
|
243
242
|
}
|
|
244
243
|
};
|
|
245
244
|
|
|
246
245
|
const handleCustomAppleSignIn = async () => {
|
|
247
246
|
try {
|
|
248
|
-
// Custom Apple sign-in logic
|
|
249
247
|
const result = await customAppleSignInFlow();
|
|
250
248
|
|
|
251
249
|
if (result.success) {
|
|
252
|
-
console.log('Apple
|
|
250
|
+
console.log('Apple sign-in successful');
|
|
253
251
|
}
|
|
254
252
|
} catch (error) {
|
|
255
|
-
Alert.alert('
|
|
253
|
+
Alert.alert('Error', 'Apple sign-in failed');
|
|
256
254
|
}
|
|
257
255
|
};
|
|
258
256
|
|
|
@@ -279,7 +277,7 @@ function AuthBottomSheetWithCustomHandlers() {
|
|
|
279
277
|
}
|
|
280
278
|
```
|
|
281
279
|
|
|
282
|
-
### Auth Modal
|
|
280
|
+
### Triggering Auth Modal
|
|
283
281
|
|
|
284
282
|
```typescript
|
|
285
283
|
function RequireAuthButton() {
|
|
@@ -288,24 +286,24 @@ function RequireAuthButton() {
|
|
|
288
286
|
|
|
289
287
|
const handlePress = () => {
|
|
290
288
|
if (!isAuthenticated) {
|
|
291
|
-
//
|
|
289
|
+
// Show login modal
|
|
292
290
|
showAuthModal(undefined, 'login');
|
|
293
291
|
return;
|
|
294
292
|
}
|
|
295
293
|
|
|
296
|
-
//
|
|
297
|
-
console.log('
|
|
294
|
+
// Perform auth-required action
|
|
295
|
+
console.log('Action successful');
|
|
298
296
|
};
|
|
299
297
|
|
|
300
298
|
return (
|
|
301
299
|
<Button onPress={handlePress}>
|
|
302
|
-
Auth
|
|
300
|
+
Auth Required Action
|
|
303
301
|
</Button>
|
|
304
302
|
);
|
|
305
303
|
}
|
|
306
304
|
```
|
|
307
305
|
|
|
308
|
-
### Pending Callback
|
|
306
|
+
### With Pending Callback
|
|
309
307
|
|
|
310
308
|
```typescript
|
|
311
309
|
function AddToFavoritesButton() {
|
|
@@ -314,45 +312,45 @@ function AddToFavoritesButton() {
|
|
|
314
312
|
|
|
315
313
|
const handleAddToFavorites = async () => {
|
|
316
314
|
if (!isAuthenticated) {
|
|
317
|
-
//
|
|
315
|
+
// Save callback to run after successful auth
|
|
318
316
|
showAuthModal(async () => {
|
|
319
317
|
await addToFavorites(postId);
|
|
320
|
-
Alert.alert('
|
|
318
|
+
Alert.alert('Success', 'Added to favorites');
|
|
321
319
|
}, 'login');
|
|
322
320
|
return;
|
|
323
321
|
}
|
|
324
322
|
|
|
325
|
-
//
|
|
323
|
+
// User authenticated, perform action directly
|
|
326
324
|
await addToFavorites(postId);
|
|
327
|
-
Alert.alert('
|
|
325
|
+
Alert.alert('Success', 'Added to favorites');
|
|
328
326
|
};
|
|
329
327
|
|
|
330
328
|
return (
|
|
331
329
|
<Button onPress={handleAddToFavorites}>
|
|
332
|
-
|
|
330
|
+
Add to Favorites
|
|
333
331
|
</Button>
|
|
334
332
|
);
|
|
335
333
|
}
|
|
336
334
|
```
|
|
337
335
|
|
|
338
|
-
##
|
|
336
|
+
## Auto-Close Behavior
|
|
339
337
|
|
|
340
|
-
|
|
338
|
+
The hook automatically closes the modal after successful authentication:
|
|
341
339
|
|
|
342
|
-
- **
|
|
343
|
-
- **Anonymous
|
|
340
|
+
- **Not authenticated → Authenticated**: User signs in/logs in
|
|
341
|
+
- **Anonymous → Authenticated**: Anonymous user registers
|
|
344
342
|
|
|
345
343
|
```typescript
|
|
346
|
-
//
|
|
347
|
-
// → useAuth store
|
|
348
|
-
// → useAuthBottomSheet
|
|
349
|
-
// → Modal
|
|
350
|
-
// → Pending callback
|
|
344
|
+
// User signs in
|
|
345
|
+
// → useAuth store updates
|
|
346
|
+
// → useAuthBottomSheet detects this
|
|
347
|
+
// → Modal auto-closes
|
|
348
|
+
// → Pending callback executes
|
|
351
349
|
```
|
|
352
350
|
|
|
353
|
-
## Provider
|
|
351
|
+
## Provider Detection
|
|
354
352
|
|
|
355
|
-
|
|
353
|
+
The hook automatically determines which providers are available:
|
|
356
354
|
|
|
357
355
|
```typescript
|
|
358
356
|
const { providers } = useAuthBottomSheet({
|
|
@@ -362,12 +360,12 @@ const { providers } = useAuthBottomSheet({
|
|
|
362
360
|
},
|
|
363
361
|
});
|
|
364
362
|
|
|
365
|
-
// iOS: ['apple', 'google']
|
|
363
|
+
// iOS: ['apple', 'google'] or ['google']
|
|
366
364
|
// Android: ['google']
|
|
367
365
|
// Web: ['google']
|
|
368
366
|
```
|
|
369
367
|
|
|
370
|
-
##
|
|
368
|
+
## Error Handling
|
|
371
369
|
|
|
372
370
|
```typescript
|
|
373
371
|
function AuthBottomSheetWithErrorHandling() {
|
|
@@ -386,32 +384,31 @@ function AuthBottomSheetWithErrorHandling() {
|
|
|
386
384
|
const handleGoogleSignInWithErrorHandling = async () => {
|
|
387
385
|
try {
|
|
388
386
|
await handleGoogleSignIn();
|
|
389
|
-
// Hook hata yönetimini içeride yapar
|
|
390
387
|
} catch (error) {
|
|
391
388
|
// Additional error handling if needed
|
|
392
|
-
Alert.alert('
|
|
389
|
+
Alert.alert('Error', 'Something went wrong');
|
|
393
390
|
}
|
|
394
391
|
};
|
|
395
392
|
|
|
396
393
|
return (
|
|
397
394
|
<BottomSheetModal ref={modalRef}>
|
|
398
395
|
<Button onPress={handleGoogleSignInWithErrorHandling}>
|
|
399
|
-
|
|
396
|
+
Sign in with Google
|
|
400
397
|
</Button>
|
|
401
398
|
</BottomSheetModal>
|
|
402
399
|
);
|
|
403
400
|
}
|
|
404
401
|
```
|
|
405
402
|
|
|
406
|
-
##
|
|
403
|
+
## Related Components
|
|
407
404
|
|
|
408
|
-
- [`AuthBottomSheet`](../components/AuthBottomSheet.md) - Bottom sheet component
|
|
409
|
-
- [`useAuthModalStore`](../stores/authModalStore.md) - Auth modal state store
|
|
410
|
-
- [`LoginForm`](../components/LoginForm.md) - Login form component
|
|
411
|
-
- [`RegisterForm`](../components/RegisterForm.md) - Register form component
|
|
405
|
+
- [`AuthBottomSheet`](../components/AuthBottomSheet.md) - Bottom sheet component
|
|
406
|
+
- [`useAuthModalStore`](../stores/authModalStore.md) - Auth modal state store
|
|
407
|
+
- [`LoginForm`](../components/LoginForm.md) - Login form component
|
|
408
|
+
- [`RegisterForm`](../components/RegisterForm.md) - Register form component
|
|
412
409
|
|
|
413
|
-
##
|
|
410
|
+
## Related Hooks
|
|
414
411
|
|
|
415
|
-
- [`useGoogleAuth`](./useSocialLogin.md#usegoogleauth) - Google auth hook
|
|
416
|
-
- [`useAppleAuth`](./useSocialLogin.md#useappleauth) - Apple auth hook
|
|
417
|
-
- [`useAuth`](./useAuth.md) -
|
|
412
|
+
- [`useGoogleAuth`](./useSocialLogin.md#usegoogleauth) - Google auth hook
|
|
413
|
+
- [`useAppleAuth`](./useSocialLogin.md#useappleauth) - Apple auth hook
|
|
414
|
+
- [`useAuth`](./useAuth.md) - Main auth state management
|