@umituz/react-native-auth 3.4.33 → 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.
@@ -1,122 +1,286 @@
1
- # Auth Hooks
1
+ # Presentation Hooks
2
2
 
3
- Collection of custom React hooks for the React Native Auth package. These hooks manage authentication operations and state.
3
+ React hooks for authentication state and operations.
4
4
 
5
- ## Available Hooks
5
+ ---
6
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
7
+ ## Strategy
11
8
 
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
9
+ **Purpose**: Provides React hooks for managing authentication state and operations in components. Single source of truth for auth state.
16
10
 
17
- ### Account Management Hooks
18
- - **[`useAccountManagement`](./useAccountManagement.md)** - Account deletion, logout, etc.
11
+ **When to Use**:
12
+ - Need authentication state in component
13
+ - Performing auth operations
14
+ - Checking user permissions
15
+ - Managing user profiles
19
16
 
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
17
+ **Location**: `src/presentation/hooks/`
24
18
 
25
- ### Form Hooks
26
- - **[`useLoginForm`](./useLoginForm.md)** - Login form state management
27
- - **[`useRegisterForm`](./useRegisterForm.md)** - Registration form state management
19
+ ---
28
20
 
29
- ### UI Hooks
30
- - **[`useAuthBottomSheet`](./useAuthBottomSheet.md)** - Auth bottom sheet management
21
+ ## Core Hooks
31
22
 
32
- ### Mutation Hooks
33
- - **[`useAuthMutations`](./mutations/useAuthMutations.md)** - Auth mutation operations
23
+ ### useAuth
34
24
 
35
- ## Usage
25
+ **PRIMARY AUTH HOOK**
36
26
 
27
+ **Purpose**: Core authentication state and operations
28
+
29
+ **When to Use**:
30
+ - Need auth state anywhere in app
31
+ - Performing sign in/up/out
32
+ - Checking authentication status
33
+ - Getting user information
34
+
35
+ **Import Path**:
36
+ ```typescript
37
+ import { useAuth } from '@umituz/react-native-auth';
38
+ ```
39
+
40
+ **File**: `useAuth.ts`
41
+
42
+ **Rules**:
43
+ - MUST initialize AuthProvider before use
44
+ - MUST handle loading state
45
+ - MUST check auth readiness before operations
46
+ - MUST handle errors appropriately
47
+
48
+ **MUST NOT**:
49
+ - Use without AuthProvider
50
+ - Ignore loading states
51
+ - Assume user is authenticated
52
+
53
+ **State Properties**:
54
+ - `user` - Firebase user object
55
+ - `userId` - User UID
56
+ - `userType` - User type enum
57
+ - `loading` - Initial auth check loading
58
+ - `isAuthReady` - Auth check complete
59
+ - `isAuthenticated` - User logged in
60
+ - `isAnonymous` - Anonymous user
61
+ - `error` - Error message
62
+
63
+ **Methods**:
64
+ - `signIn(email, password)` - Email/password login
65
+ - `signUp(email, password, displayName)` - Create account
66
+ - `signOut()` - Sign out
67
+ - `continueAnonymously()` - Anonymous session
68
+
69
+ **Documentation**: `useAuth.md`
70
+
71
+ ---
72
+
73
+ ### useAuthRequired & useRequireAuth
74
+
75
+ **Purpose**: Require authentication for components or actions
76
+
77
+ **When to Use**:
78
+ - Protecting components/routes
79
+ - Checking auth before actions
80
+ - Conditional rendering based on auth
81
+ - Showing auth modal
82
+
83
+ **Import Path**:
37
84
  ```typescript
38
85
  import {
39
- useAuth,
40
- useUserProfile,
41
- useSocialLogin
86
+ useAuthRequired,
87
+ useRequireAuth
42
88
  } from '@umituz/react-native-auth';
89
+ ```
43
90
 
44
- function MyComponent() {
45
- const { user, signIn, signOut } = useAuth();
46
- const { profile, isLoading } = useUserProfile();
47
- const { signInWithGoogle } = useSocialLogin();
91
+ **File**: `useAuthRequired.ts`
48
92
 
49
- // ...
50
- }
93
+ **Rules**:
94
+ - MUST handle loading state
95
+ - MUST provide fallback for unauthenticated
96
+ - MUST check auth readiness
97
+ - MUST respect user cancellation
98
+
99
+ **Documentation**: `useAuthRequired.md`
100
+
101
+ ---
102
+
103
+ ### useUserProfile
104
+
105
+ **Purpose**: Fetch and display user profile data
106
+
107
+ **When to Use**:
108
+ - Displaying user information
109
+ - Profile headers
110
+ - Account settings
111
+ - User identification
112
+
113
+ **Import Path**:
114
+ ```typescript
115
+ import { useUserProfile } from '@umituz/react-native-auth';
51
116
  ```
52
117
 
53
- ## Hooks Documentation
118
+ **File**: `useUserProfile.ts`
119
+
120
+ **Rules**:
121
+ - MUST handle undefined return
122
+ - MUST check isAnonymous before actions
123
+ - MUST provide fallback for missing data
124
+ - MUST handle anonymous users appropriately
54
125
 
55
- See each hook's documentation for detailed usage information and examples.
126
+ **Documentation**: `useUserProfile.md`
56
127
 
57
- ## Quick Reference
128
+ ---
58
129
 
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 |
130
+ ### useProfileUpdate & useProfileEdit
72
131
 
73
- ## Best Practices
132
+ **Purpose**: Profile update operations and form management
74
133
 
75
- ### 1. Use Appropriate Hooks
134
+ **When to Use**:
135
+ - Profile editing screens
136
+ - Settings screens
137
+ - Form state management
138
+ - Profile modifications
76
139
 
140
+ **Import Path**:
77
141
  ```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
- }
142
+ import {
143
+ useProfileUpdate,
144
+ useProfileEdit
145
+ } from '@umituz/react-native-auth';
87
146
  ```
88
147
 
89
- ### 2. Handle Loading States
148
+ **File**: `useProfileUpdate.ts`
149
+
150
+ **Rules**:
151
+ - MUST validate before update
152
+ - MUST handle loading state
153
+ - MUST show errors to user
154
+ - MUST not allow anonymous updates
155
+
156
+ **Documentation**: `useProfileUpdate.md`
157
+
158
+ ---
159
+
160
+ ### useAccountManagement
161
+
162
+ **Purpose**: Account operations (logout, delete)
163
+
164
+ **When to Use**:
165
+ - Account settings screens
166
+ - Logout functionality
167
+ - Account deletion
168
+ - Password changes
90
169
 
170
+ **Import Path**:
91
171
  ```typescript
92
- // Good
93
- function Component() {
94
- const { loading, isAuthReady, user } = useAuth();
172
+ import { useAccountManagement } from '@umituz/react-native-auth';
173
+ ```
174
+
175
+ **File**: `useAccountManagement.ts`
176
+
177
+ **Rules**:
178
+ - MUST confirm before destructive actions
179
+ - MUST handle reauthentication
180
+ - MUST show clear warnings
181
+ - MUST hide for anonymous users
182
+
183
+ **Documentation**: `useAccountManagement.md`
95
184
 
96
- if (loading) return <LoadingSpinner />;
97
- if (!isAuthReady) return <InitializingScreen />;
98
- if (!user) return <LoginScreen />;
185
+ ---
99
186
 
100
- return <HomeScreen />;
101
- }
187
+ ### useSocialLogin
188
+
189
+ **Purpose**: Google and Apple authentication
190
+
191
+ **When to Use**:
192
+ - Social authentication needed
193
+ - Want Google sign-in
194
+ - Want Apple sign-in (iOS)
195
+ - Unified social auth interface
196
+
197
+ **Import Path**:
198
+ ```typescript
199
+ import {
200
+ useSocialLogin,
201
+ useGoogleAuth,
202
+ useAppleAuth
203
+ } from '@umituz/react-native-auth';
102
204
  ```
103
205
 
104
- ### 3. Use Selectors for Performance
206
+ **File**: `useSocialLogin.ts`
207
+
208
+ **Rules**:
209
+ - MUST configure providers before use
210
+ - MUST check provider availability
211
+ - MUST handle loading states
212
+ - MUST handle platform differences
213
+
214
+ **Documentation**: `useSocialLogin.md`
215
+
216
+ ---
217
+
218
+ ### useAuthBottomSheet
219
+
220
+ **Purpose**: Auth modal management
221
+
222
+ **When to Use**:
223
+ - Modal-based authentication
224
+ - Login/register modal
225
+ - Social auth in modal
226
+ - Pending callback execution
105
227
 
228
+ **Import Path**:
106
229
  ```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
- }
230
+ import { useAuthBottomSheet } from '@umituz/react-native-auth';
116
231
  ```
117
232
 
233
+ **File**: `useAuthBottomSheet.ts`
234
+
235
+ **Rules**:
236
+ - MUST use with BottomSheetModal component
237
+ - MUST handle modal lifecycle
238
+ - MUST execute pending callbacks
239
+ - MUST reset state properly
240
+
241
+ **Documentation**: `useAuthBottomSheet.md`
242
+
243
+ ---
244
+
245
+ ## Hook Usage Patterns
246
+
247
+ ### Initialization
248
+
249
+ **RULES**:
250
+ - MUST wrap app with AuthProvider
251
+ - MUST initialize Firebase before AuthProvider
252
+ - MUST handle initialization errors
253
+ - MUST not use hooks outside provider
254
+
255
+ **ORDER**:
256
+ 1. Initialize Firebase
257
+ 2. Wrap with AuthProvider
258
+ 3. Use hooks in components
259
+
260
+ ---
261
+
262
+ ### Error Handling
263
+
264
+ **RULES**:
265
+ - MUST wrap hook calls in try-catch
266
+ - MUST display error messages
267
+ - MUST allow user retry
268
+ - MUST not expose sensitive errors
269
+
270
+ ---
271
+
272
+ ### Performance
273
+
274
+ **RULES**:
275
+ - MUST not call hooks conditionally
276
+ - MUST use hook dependencies correctly
277
+ - MUST not create multiple auth listeners
278
+ - MUST memoize expensive computations
279
+
280
+ ---
281
+
118
282
  ## Related Documentation
119
283
 
120
- - **[Components](../components/README.md)** - UI components
121
- - **[Services](../../infrastructure/services/README.md)** - Core services
122
- - **[Domain](../../domain/README.md)** - Domain entities
284
+ - **Components**: `../components/README.md`
285
+ - **Screens**: `../screens/README.md`
286
+ - **Stores**: `../stores/README.md`