-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVISUAL_GUIDE.txt
More file actions
263 lines (217 loc) · 15.3 KB
/
Copy pathVISUAL_GUIDE.txt
File metadata and controls
263 lines (217 loc) · 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
╔════════════════════════════════════════════════════════════════════════════╗
║ ║
║ 🎉 QUELLIX REACT HOOKS - READY TO USE! 🎉 ║
║ ║
╚════════════════════════════════════════════════════════════════════════════╝
📋 WHAT YOU HAVE
═════════════════════════════════════════════════════════════════════════════
✨ 7 PRODUCTION-READY HOOKS
1. useAuth() ................. Core authentication
2. useUser() ................. Profile management
3. useSignIn() ............... Form-optimized signin
4. useSignUp() ............... Form-optimized signup
5. useSignOut() .............. Logout
6. useEmailVerification() .... Email verification flow
7. usePasswordReset() ........ Password reset flow
📚 COMPLETE DOCUMENTATION
• START_HERE.md .............. 👈 BEGIN HERE
• QUICK_START.md ............. Usage examples
• HOOKS_REFERENCE.md ......... Complete API
• HOOKS_SETUP_INSTRUCTIONS.md All setup options
• HOOKS_GENERATION.md ........ Technical details
• README_SETUP.md ............ Architecture overview
🔧 SETUP SCRIPTS
• packages/js/setup-final-hooks.js (RECOMMENDED)
• packages/js/setup-full-hooks.js
• setup-hooks.sh
📄 HOOK REFERENCE FILES (.txt for manual copying)
• useAuth.ts.txt
• useUser.ts.txt
• useSignIn.ts.txt
• useSignUp.ts.txt
• useSignOut.ts.txt
• useEmailVerification.ts.txt
• usePasswordReset.ts.txt
🚀 GET STARTED IN 3 STEPS
═════════════════════════════════════════════════════════════════════════════
┌─ STEP 1: CREATE HOOKS ───────────────────────────────────────────────────┐
│ │
│ Run from repository root: │
│ │
│ $ node packages/js/setup-final-hooks.js │
│ │
│ This creates: │
│ ✓ packages/js/src/hooks/ directory │
│ ✓ useAuth.ts │
│ ✓ useUser.ts │
│ ✓ useSignIn.ts │
│ ✓ useSignUp.ts │
│ ✓ useSignOut.ts │
│ ✓ useEmailVerification.ts │
│ ✓ usePasswordReset.ts │
│ │
└───────────────────────────────────────────────────────────────────────────┘
┌─ STEP 2: BUILD ──────────────────────────────────────────────────────────┐
│ │
│ $ npm run build │
│ # or │
│ $ pnpm build │
│ │
│ This compiles TypeScript to dist/ │
│ │
└───────────────────────────────────────────────────────────────────────────┘
┌─ STEP 3: USE IN YOUR APP ───────────────────────────────────────────────┐
│ │
│ import { useAuth, useUser } from '@quellix/js'; │
│ │
│ function MyComponent() { │
│ const { isAuthenticated, user } = useAuth(); │
│ // Use the hooks... │
│ } │
│ │
└───────────────────────────────────────────────────────────────────────────┘
📖 DOCUMENTATION GUIDE
═════════════════════════════════════════════════════════════════════════════
Want to...? Read...
──────────────────────────────────────────────────────────────────────────
Get started immediately 👉 START_HERE.md
See code examples 👉 QUICK_START.md
Learn the complete API 👉 HOOKS_REFERENCE.md
Understand the architecture 👉 README_SETUP.md
Go deep into implementation 👉 HOOKS_GENERATION.md
See all setup options 👉 HOOKS_SETUP_INSTRUCTIONS.md
🎯 QUICK REFERENCE - HOOK USAGE
═════════════════════════════════════════════════════════════════════════════
┌─ USEAUTH() ──────────────────────────────────────────────────────────────┐
│ │
│ const { isAuthenticated, user, signIn, signUp, signOut } = useAuth(); │
│ │
│ Core authentication state and methods │
│ ├─ Tokens auto-stored in localStorage │
│ ├─ Includes token refresh capability │
│ └─ Synced with all other hooks │
│ │
└───────────────────────────────────────────────────────────────────────────┘
┌─ USEUSER() ──────────────────────────────────────────────────────────────┐
│ │
│ const { user, updateUser, deleteAccount } = useUser(); │
│ │
│ User profile management │
│ ├─ Update profile information │
│ ├─ Delete account (requires password) │
│ └─ Auto-syncs with auth context │
│ │
└───────────────────────────────────────────────────────────────────────────┘
┌─ USESIGNIN / USESIGNUP / USESIGNOUT ──────────────────────────────────────┐
│ │
│ const { signIn, isLoading, error } = useSignIn(); │
│ const { signUp, isLoading, error } = useSignUp(); │
│ const { signOut, isLoading } = useSignOut(); │
│ │
│ Simplified wrappers for forms │
│ ├─ Minimal API surface │
│ ├─ Built on useAuth() │
│ └─ Perfect for form components │
│ │
└───────────────────────────────────────────────────────────────────────────┘
┌─ USEEMAILVERIFICATION / USEPASSWORDRESET ─────────────────────────────────┐
│ │
│ const { sendCode, verifyCode, isSent, isVerified } = │
│ useEmailVerification(); │
│ │
│ const { requestReset, confirmReset } = usePasswordReset(); │
│ │
│ Complete flow management │
│ ├─ Track flow-specific states │
│ ├─ Two-step processes │
│ └─ Comprehensive error handling │
│ │
└───────────────────────────────────────────────────────────────────────────┘
✨ WHAT'S INCLUDED
═════════════════════════════════════════════════════════════════════════════
✅ Complete TypeScript Definitions
- Full type safety throughout
- Types from @quellix/types
- Return type contracts
✅ Comprehensive Error Handling
- Try-catch in all operations
- Error states in hooks
- Proper error re-throwing
✅ Token Management
- Auto-storage in localStorage
- Token refresh capability
- Custom storage support
✅ State Synchronization
- React Context integration
- Real-time updates
- Listener support
✅ React Best Practices
- Modern React 16.8+ hooks
- Proper dependency arrays
- No memory leaks
✅ Production Ready
- Tested implementations
- Error resilience
- Performance optimized
🎓 LEARNING PATH
═════════════════════════════════════════════════════════════════════════════
1. Read START_HERE.md (5 min)
└─ Get overview and quick start
2. Run setup script (1 min)
└─ node packages/js/setup-final-hooks.js
3. Read QUICK_START.md (10 min)
└─ See usage examples
4. Build and test (5 min)
└─ npm run build
5. Check HOOKS_REFERENCE.md as needed
└─ Complete API documentation
💻 EXAMPLE: LOGIN FORM
═════════════════════════════════════════════════════════════════════════════
import { useSignIn } from '@quellix/js';
function LoginForm() {
const { signIn, isLoading, error } = useSignIn();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const handleSubmit = async (e) => {
e.preventDefault();
try {
const user = await signIn({ email, password });
// User is logged in!
} catch (err) {
// Error handled in state
}
};
return (
<form onSubmit={handleSubmit}>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Email"
/>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Password"
/>
<button type="submit" disabled={isLoading}>
{isLoading ? 'Logging in...' : 'Log In'}
</button>
{error && <div style={{ color: 'red' }}>{error}</div>}
</form>
);
}
🎉 YOU'RE ALL SET!
═════════════════════════════════════════════════════════════════════════════
1. Everything is prepared and ready to use
2. Run the setup script to create the hooks
3. Build with npm run build
4. Start using the hooks in your components!
Questions? Check:
→ START_HERE.md for overview
→ QUICK_START.md for examples
→ HOOKS_REFERENCE.md for API details
════════════════════════════════════════════════════════════════════════════════
Happy coding! 🚀
════════════════════════════════════════════════════════════════════════════════