@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.
@@ -0,0 +1,340 @@
1
+ # SocialLoginButtons
2
+
3
+ Component that displays Google and Apple social authentication buttons.
4
+
5
+ ---
6
+
7
+ ## Component Overview
8
+
9
+ ### Strategy
10
+
11
+ **Purpose**: Provides pre-built social authentication buttons for Google and Apple with consistent styling, loading states, and platform-specific behavior.
12
+
13
+ **When to Use**:
14
+ - Adding social login options to authentication screens
15
+ - Need quick integration with OAuth providers
16
+ - Want consistent social login UI across app
17
+ - Supporting multiple social providers
18
+
19
+ **Import Path**:
20
+ ```typescript
21
+ import { SocialLoginButtons } from '@umituz/react-native-auth';
22
+ ```
23
+
24
+ **Component Location**: `src/presentation/components/SocialLoginButtons.tsx`
25
+
26
+ ---
27
+
28
+ ## Provider Configuration
29
+
30
+ ### Strategy
31
+
32
+ **Purpose**: Configure which social providers to display based on platform and availability.
33
+
34
+ **Supported Providers**:
35
+ - `google` - Google OAuth (all platforms)
36
+ - `apple` - Apple Sign In (iOS only)
37
+
38
+ ### Rules
39
+
40
+ **MUST**:
41
+ - Pass `enabledProviders` array with provider names
42
+ - Check provider availability before enabling
43
+ - Provide press handlers for enabled providers
44
+ - Respect platform restrictions (Apple = iOS only)
45
+
46
+ **MUST NOT**:
47
+ - Enable Apple on Android or Web
48
+ - Show provider buttons without press handlers
49
+ - Assume provider is available without checking
50
+
51
+ ### Constraints
52
+
53
+ **PLATFORM AVAILABILITY**:
54
+ | Provider | iOS | Android | Web |
55
+ |----------|-----|---------|-----|
56
+ | Google | ✅ | ✅ | ✅ |
57
+ | Apple | ✅ | ❌ | ❌ |
58
+
59
+ **PROVIDER DETECTION**:
60
+ - Use `useGoogleAuth` hook to check Google availability
61
+ - Use `useAppleAuth` hook to check Apple availability
62
+ - Filter enabled providers array based on availability
63
+
64
+ **CONFIGURATION REQUIREMENTS**:
65
+ - Google: Requires client ID configuration
66
+ - Apple: Requires Apple Developer account
67
+ - Both: Requires Firebase project setup
68
+
69
+ ---
70
+
71
+ ## Button State Management
72
+
73
+ ### Strategy
74
+
75
+ **Purpose**: Provide visual feedback for loading, disabled, and error states.
76
+
77
+ ### Rules
78
+
79
+ **MUST**:
80
+ - Show loading indicator during OAuth flow
81
+ - Disable buttons during authentication
82
+ - Re-enable buttons after completion (success or error)
83
+ - Handle user cancellation gracefully
84
+
85
+ **MUST NOT**:
86
+ - Leave buttons in loading state indefinitely
87
+ - Allow multiple simultaneous OAuth requests
88
+ - Show loading without active OAuth flow
89
+
90
+ ### Constraints
91
+
92
+ **LOADING STATES**:
93
+ - `googleLoading` - Show Google button in loading state
94
+ - `appleLoading` - Show Apple button in loading state
95
+ - Loading overrides disabled state visually
96
+
97
+ **DISABLED STATES**:
98
+ - Global disabled: All buttons disabled
99
+ - Per-button loading: Only that button disabled
100
+ - Parent form disabled: All social buttons disabled
101
+
102
+ **ERROR RECOVERY**:
103
+ - Auto-recover after cancellation
104
+ - Manual retry required after errors
105
+ - No retry limit (user can try indefinitely)
106
+
107
+ ---
108
+
109
+ ## Platform-Specific Behavior
110
+
111
+ ### Strategy
112
+
113
+ **Purpose**: Optimize social login experience for each platform's conventions.
114
+
115
+ ### Rules
116
+
117
+ **MUST**:
118
+ - Hide Apple button on non-iOS platforms
119
+ - Use platform-appropriate button styles
120
+ - Follow platform OAuth flow conventions
121
+ - Respect platform-specific limitations
122
+
123
+ **MUST NOT**:
124
+ - Show Apple button on Android
125
+ - Force web OAuth flow on native platforms
126
+ - Bypass platform security features
127
+
128
+ ### Constraints
129
+
130
+ **iOS BEHAVIOR**:
131
+ - Apple Sign-In uses native credential UI
132
+ - Google uses app-based OAuth when available
133
+ - Falls back to web OAuth if needed
134
+ - Requires Info.plist configuration
135
+
136
+ **ANDROID BEHAVIOR**:
137
+ - Google uses app-based OAuth
138
+ - Apple button hidden
139
+ - Requires Firebase configuration
140
+ - Requires Google Services JSON
141
+
142
+ **WEB BEHAVIOR**:
143
+ - Both providers use popup/redirect OAuth
144
+ - Requires proper callback handling
145
+ - Requires auth session setup
146
+ - Browser popup blockers may interfere
147
+
148
+ ---
149
+
150
+ ## Error Handling
151
+
152
+ ### Strategy
153
+
154
+ **Purpose**: Gracefully handle OAuth errors without breaking user experience.
155
+
156
+ ### Rules
157
+
158
+ **MUST**:
159
+ - Distinguish between user cancellation and errors
160
+ - Show user-friendly error messages
161
+ - Allow retry after errors
162
+ - Log errors for debugging (not to user)
163
+
164
+ **MUST NOT**:
165
+ - Show raw OAuth errors to users
166
+ - Block retry after errors
167
+ - Crash or hang on OAuth failure
168
+ - Expose sensitive tokens in errors
169
+
170
+ ### Constraints
171
+
172
+ **ERROR TYPES**:
173
+ - User cancellation: Silent or gentle notification
174
+ - Network error: Retry prompt
175
+ - Configuration error: Developer-focused message
176
+ - Provider error: Generic "try again" message
177
+
178
+ **ERROR DISPLAY**:
179
+ - Alert/Modal for critical errors
180
+ - Inline text for non-critical errors
181
+ - Toast for success/cancellation
182
+ - Console logging for debugging
183
+
184
+ ---
185
+
186
+ ## Security Requirements
187
+
188
+ ### Strategy
189
+
190
+ **Purpose**: Ensure OAuth authentication follows security best practices.
191
+
192
+ ### Rules
193
+
194
+ **MUST**:
195
+ - Use HTTPS for all OAuth endpoints
196
+ - Store tokens securely (Keychain/Keystore)
197
+ - Never log tokens or credentials
198
+ - Validate tokens server-side
199
+ - Implement token refresh logic
200
+
201
+ **MUST NOT**:
202
+ - Store tokens in AsyncStorage/localStorage
203
+ - Log OAuth responses with tokens
204
+ - Skip server-side token validation
205
+ - Use HTTP for OAuth flows
206
+ - Expose client secrets in app code
207
+
208
+ ### Constraints
209
+
210
+ **TOKEN HANDLING**:
211
+ - Tokens managed by Firebase SDK
212
+ - App never directly accesses refresh tokens
213
+ - ID tokens accessible for API calls
214
+ - Secure storage handled automatically
215
+
216
+ **CLIENT SECRETS**:
217
+ - Never include client secrets in app
218
+ - Use public client flows
219
+ - Server-side validation required
220
+ - Firebase manages OAuth credentials
221
+
222
+ ---
223
+
224
+ ## Localization
225
+
226
+ ### Strategy
227
+
228
+ **Purpose**: Support international users with localized button text and messages.
229
+
230
+ ### Rules
231
+
232
+ **MUST**:
233
+ - Use localization keys for all text
234
+ - Provide translations for supported languages
235
+ - Respect user's language preference
236
+ - Format error messages appropriately
237
+
238
+ **MUST NOT**:
239
+ - Hardcode English text
240
+ - Assume user speaks English
241
+ - Mix languages in UI
242
+
243
+ ### Constraints
244
+
245
+ **LOCALIZATION KEYS**:
246
+ ```
247
+ auth.orContinueWith
248
+ auth.google
249
+ auth.apple
250
+ auth.signingIn
251
+ ```
252
+
253
+ **SUPPORTED LANGUAGES**:
254
+ - English (default)
255
+ - Turkish
256
+ - Add more via i18n configuration
257
+
258
+ ---
259
+
260
+ ## Design System Integration
261
+
262
+ ### Strategy
263
+
264
+ **Purpose**: Consistent styling with application design system.
265
+
266
+ ### Rules
267
+
268
+ **MUST**:
269
+ - Use design system color tokens
270
+ - Follow design system spacing
271
+ - Match design system button styles
272
+ - Use design system icons/logos
273
+
274
+ **MUST NOT**:
275
+ - Hardcode colors or sizes
276
+ - Use unofficial provider logos
277
+ - Override design system styles
278
+
279
+ ### Constraints
280
+
281
+ **STYLE TOKENS**:
282
+ - Button colors: Design system primary
283
+ - Text colors: Design system text tokens
284
+ - Spacing: Design system spacing scale
285
+ - Border radius: Design system radius tokens
286
+
287
+ **PROVIDER BRANDING**:
288
+ - Use official Google/Apple logos
289
+ - Follow provider brand guidelines
290
+ - Maintain minimum logo sizes
291
+ - Don't modify logo colors
292
+
293
+ ---
294
+
295
+ ## Analytics Integration
296
+
297
+ ### Strategy
298
+
299
+ **Purpose**: Track social login usage for analytics and optimization.
300
+
301
+ ### Rules
302
+
303
+ **MUST**:
304
+ - Track login attempts per provider
305
+ - Track successful logins
306
+ - Track failures (without sensitive data)
307
+ - Track cancellation rates
308
+
309
+ **MUST NOT**:
310
+ - Log personally identifiable information
311
+ - Log OAuth tokens or credentials
312
+ - Track before user consents
313
+ - Expose raw analytics data to users
314
+
315
+ ### Constraints
316
+
317
+ **EVENTS TO TRACK**:
318
+ - `social_login_attempt` (provider, platform)
319
+ - `social_login_success` (provider, platform)
320
+ - `social_login_failed` (provider, error_category)
321
+ - `social_login_cancelled` (provider, platform)
322
+
323
+ **PRIVACY**:
324
+ - No user data in events
325
+ - No session identifiers in events
326
+ - Aggregate data only
327
+ - GDPR/CCPA compliant
328
+
329
+ ---
330
+
331
+ ## Related Components
332
+
333
+ - **`LoginForm`** (`src/presentation/components/LoginForm.tsx`) - Email/password form
334
+ - **`RegisterForm`** (`src/presentation/components/RegisterForm.tsx`) - Registration form
335
+
336
+ ## Related Hooks
337
+
338
+ - **`useGoogleAuth`** (`src/presentation/hooks/useSocialLogin.ts`) - Google authentication
339
+ - **`useAppleAuth`** (`src/presentation/hooks/useSocialLogin.ts`) - Apple authentication
340
+ - **`useSocialLogin`** (`src/presentation/hooks/useSocialLogin.ts`) - Combined social auth
@@ -0,0 +1,122 @@
1
+ # Auth Hooks
2
+
3
+ Collection of custom React hooks for the React Native Auth package. These hooks manage authentication operations and state.
4
+
5
+ ## Available Hooks
6
+
7
+ ### Core Hooks
8
+ - **[`useAuth`](./useAuth.md)** - Main authentication state and operations
9
+ - **[`useAuthRequired`](./useAuthRequired.md)** - For components requiring auth
10
+ - **[`useRequireAuth`](./useRequireAuth.md)** - Alternative hook for route protection
11
+
12
+ ### User Profile Hooks
13
+ - **[`useUserProfile`](./useUserProfile.md)** - Fetch user profile data
14
+ - **[`useProfileUpdate`](./useProfileUpdate.md)** - Profile update operations
15
+ - **[`useProfileEdit`](./useProfileEdit.md)** - Profile editing form state
16
+
17
+ ### Account Management Hooks
18
+ - **[`useAccountManagement`](./useAccountManagement.md)** - Account deletion, logout, etc.
19
+
20
+ ### Social Login Hooks
21
+ - **[`useSocialLogin`](./useSocialLogin.md)** - General social login management
22
+ - **[`useGoogleAuth`](./useSocialLogin.md#usegoogleauth)** - Google sign-in
23
+ - **[`useAppleAuth`](./useSocialLogin.md#useappleauth)** - Apple sign-in
24
+
25
+ ### Form Hooks
26
+ - **[`useLoginForm`](./useLoginForm.md)** - Login form state management
27
+ - **[`useRegisterForm`](./useRegisterForm.md)** - Registration form state management
28
+
29
+ ### UI Hooks
30
+ - **[`useAuthBottomSheet`](./useAuthBottomSheet.md)** - Auth bottom sheet management
31
+
32
+ ### Mutation Hooks
33
+ - **[`useAuthMutations`](./mutations/useAuthMutations.md)** - Auth mutation operations
34
+
35
+ ## Usage
36
+
37
+ ```typescript
38
+ import {
39
+ useAuth,
40
+ useUserProfile,
41
+ useSocialLogin
42
+ } from '@umituz/react-native-auth';
43
+
44
+ function MyComponent() {
45
+ const { user, signIn, signOut } = useAuth();
46
+ const { profile, isLoading } = useUserProfile();
47
+ const { signInWithGoogle } = useSocialLogin();
48
+
49
+ // ...
50
+ }
51
+ ```
52
+
53
+ ## Hooks Documentation
54
+
55
+ See each hook's documentation for detailed usage information and examples.
56
+
57
+ ## Quick Reference
58
+
59
+ | Hook | Purpose | Returns |
60
+ |------|---------|---------|
61
+ | `useAuth` | Main auth state | `UseAuthResult` |
62
+ | `useAuthRequired` | Check auth + show modal | `UseAuthRequiredResult` |
63
+ | `useRequireAuth` | Get userId or throw | `string` |
64
+ | `useUserProfile` | Fetch profile data | `UserProfileData \| undefined` |
65
+ | `useProfileUpdate` | Update profile | `UseProfileUpdateReturn` |
66
+ | `useProfileEdit` | Edit profile form | `UseProfileEditReturn` |
67
+ | `useAccountManagement` | Account operations | `UseAccountManagementReturn` |
68
+ | `useSocialLogin` | Social login | `UseSocialLoginResult` |
69
+ | `useGoogleAuth` | Google auth | `UseGoogleAuthResult` |
70
+ | `useAppleAuth` | Apple auth | `UseAppleAuthResult` |
71
+ | `useAuthBottomSheet` | Bottom sheet | Modal ref + handlers |
72
+
73
+ ## Best Practices
74
+
75
+ ### 1. Use Appropriate Hooks
76
+
77
+ ```typescript
78
+ // ✅ Good - Use useAuth for general auth
79
+ function Component() {
80
+ const { user, signIn } = useAuth();
81
+ }
82
+
83
+ // ❌ Bad - Using useRequireAuth when you don't need userId
84
+ function Component() {
85
+ const userId = useRequireAuth(); // Throws if not auth
86
+ }
87
+ ```
88
+
89
+ ### 2. Handle Loading States
90
+
91
+ ```typescript
92
+ // ✅ Good
93
+ function Component() {
94
+ const { loading, isAuthReady, user } = useAuth();
95
+
96
+ if (loading) return <LoadingSpinner />;
97
+ if (!isAuthReady) return <InitializingScreen />;
98
+ if (!user) return <LoginScreen />;
99
+
100
+ return <HomeScreen />;
101
+ }
102
+ ```
103
+
104
+ ### 3. Use Selectors for Performance
105
+
106
+ ```typescript
107
+ // ✅ Good - Selectors prevent unnecessary re-renders
108
+ function Component() {
109
+ const isAuthenticated = useAuthStore(selectIsAuthenticated);
110
+ }
111
+
112
+ // ❌ Bad - Re-renders on any state change
113
+ function Component() {
114
+ const { isAuthenticated } = useAuth();
115
+ }
116
+ ```
117
+
118
+ ## Related Documentation
119
+
120
+ - **[Components](../components/README.md)** - UI components
121
+ - **[Services](../../infrastructure/services/README.md)** - Core services
122
+ - **[Domain](../../domain/README.md)** - Domain entities