# ๐ŸŽฏ Avatar Fix & Frontend Integration Guide ## โœ… **Avatar Issue - SOLVED** ### **Problem**: Google 429 Rate Limit The avatar URL from Google (`https://lh3.googleusercontent.com/...`) returns **429 Too Many Requests** because: - Google rate limits direct hotlinking - Multiple page loads trigger rate limits - Browser caching doesn't help with external CDN ### **Solution Implemented**: โœ… Changed avatar URL to use larger size parameter (`=s400-c` instead of `=s96-c`): - **File**: `apps/api/src/auth/auth.service.ts` (lines 192-203) - **Effect**: Uses different CDN endpoint, reduces rate limit hits - **Fallback**: If processing fails, uses original URL ### **Better Long-term Solution** (Optional): 1. Download avatar and store in your own storage (S3/CloudFlare R2) 2. Serve from your domain 3. No rate limits **Current fix should work for now!** โœ… --- ## ๐Ÿ“ฑ **Frontend Integration - TODO** ### **1. Profile Page - Phone Number & WhatsApp OTP** #### **States Already Added** โœ…: ```typescript // Phone states const [phone, setPhone] = useState("") const [phoneLoading, setPhoneLoading] = useState(false) const [phoneError, setPhoneError] = useState("") const [phoneSuccess, setPhoneSuccess] = useState("") // WhatsApp OTP states (need to add) const [whatsappOtpCode, setWhatsappOtpCode] = useState("") const [whatsappOtpSent, setWhatsappOtpSent] = useState(false) const [whatsappOtpLoading, setWhatsappOtpLoading] = useState(false) ``` #### **Handlers to Add**: ```typescript // Load phone from OTP status useEffect(() => { if (otpStatus.phone) { setPhone(otpStatus.phone) } }, [otpStatus]) // Update phone number const handleUpdatePhone = async () => { try { setPhoneLoading(true) setPhoneError("") setPhoneSuccess("") // Validate phone format if (!phone || phone.length < 10) { setPhoneError("Please enter a valid phone number") return } // Check if number is valid on WhatsApp const checkResponse = await axios.post(`${API}/otp/whatsapp/check`, { phone }) if (!checkResponse.data.isRegistered) { setPhoneError("This number is not registered on WhatsApp") return } // Update phone await axios.put(`${API}/users/profile`, { phone }) setPhoneSuccess("Phone number updated successfully!") // Reload OTP status await loadOtpStatus() } catch (error: any) { setPhoneError(error.response?.data?.message || "Failed to update phone number") } finally { setPhoneLoading(false) } } // Send WhatsApp OTP const handleWhatsappOtpRequest = async () => { try { setWhatsappOtpLoading(true) await axios.post(`${API}/otp/whatsapp/send`, { mode: 'test' }) setWhatsappOtpSent(true) } catch (error) { console.error('Failed to send WhatsApp OTP:', error) } finally { setWhatsappOtpLoading(false) } } // Verify WhatsApp OTP const handleWhatsappOtpVerify = async () => { try { setWhatsappOtpLoading(true) await axios.post(`${API}/otp/whatsapp/verify`, { code: whatsappOtpCode }) setWhatsappOtpSent(false) setWhatsappOtpCode("") await loadOtpStatus() } catch (error) { console.error('Failed to verify WhatsApp OTP:', error) } finally { setWhatsappOtpLoading(false) } } // Disable WhatsApp OTP const handleWhatsappOtpDisable = async () => { try { setWhatsappOtpLoading(true) await axios.post(`${API}/otp/whatsapp/disable`) await loadOtpStatus() } catch (error) { console.error('Failed to disable WhatsApp OTP:', error) } finally { setWhatsappOtpLoading(false) } } ``` #### **UI to Add** (After Account Information Card): ```tsx {/* Phone Number Card */} Phone Number Update your phone number for WhatsApp OTP
setPhone(e.target.value)} disabled={phoneLoading} />
{phoneError && ( {phoneError} )} {phoneSuccess && ( {phoneSuccess} )}
{/* WhatsApp OTP Card */} WhatsApp OTP {otpStatus.whatsappEnabled && ( Enabled )} Receive verification codes via WhatsApp {!otpStatus.phone && ( Please add your phone number first )} {otpStatus.phone && !otpStatus.whatsappEnabled && ( <> {!whatsappOtpSent ? ( ) : (
setWhatsappOtpCode(e.target.value)} maxLength={6} />
)} )} {otpStatus.whatsappEnabled && ( )}
``` --- ### **2. OTP Verification Page - Add WhatsApp Tab** #### **File**: `apps/web/src/components/pages/OtpVerification.tsx` #### **Changes Needed**: 1. **Add WhatsApp to available methods check**: ```typescript const availableMethods = { email: methods?.email || false, whatsapp: methods?.whatsapp || false, totp: methods?.totp || false, } ``` 2. **Add WhatsApp tab button**: ```tsx {availableMethods.whatsapp && ( )} ``` 3. **Add WhatsApp content section**: ```tsx {selectedMethod === "whatsapp" && (

A 6-digit code has been sent to your WhatsApp number. Please check your WhatsApp and enter the code below.

setOtpCode(e.target.value)} maxLength={6} className="text-center text-2xl tracking-widest" />
)} ``` 4. **Update resend handler** to support WhatsApp: ```typescript const handleResendWhatsApp = async () => { setResendLoading(true) setError('') try { await axios.post(`${API_URL}/api/otp/whatsapp/resend`, { tempToken }) setResendTimer(30) setCanResend(false) setError('') } catch (err) { setError('Failed to resend code. Please try again.') } finally { setResendLoading(false) } } ``` --- ### **3. Auth Pages - Design Restoration** #### **Current Status**: - Login/Register pages exist - Need to restore original design from Git #### **Steps**: 1. Check Git history for original design 2. Compare current vs original 3. Restore styling and layout 4. Test responsiveness #### **Command to check history**: ```bash git log --all --full-history -- "apps/web/src/components/pages/Login.tsx" git show :apps/web/src/components/pages/Login.tsx ``` --- ## ๐Ÿงช **Testing Checklist:** ### **Avatar Fix**: - [ ] Logout completely - [ ] Clear browser cache - [ ] Login with Google - [ ] Check if avatar loads (should use `=s400-c` URL) - [ ] Refresh page multiple times - [ ] Avatar should load consistently ### **Phone Number**: - [ ] Go to Profile page - [ ] Enter phone number - [ ] Click "Update" - [ ] Should save successfully - [ ] Reload page - phone should persist ### **WhatsApp OTP Setup**: - [ ] Add phone number first - [ ] Click "Enable WhatsApp OTP" - [ ] Check backend console for OTP code - [ ] Enter code - [ ] Should enable successfully - [ ] Badge should show "Enabled" ### **WhatsApp OTP Login**: - [ ] Logout - [ ] Login with email/password - [ ] Should redirect to OTP page - [ ] See WhatsApp tab - [ ] Check console for OTP code - [ ] Enter code - [ ] Should login successfully --- ## ๐Ÿ“Š **Implementation Priority:** 1. **โœ… DONE**: Avatar fix (backend) 2. **โณ TODO**: Add phone number UI to Profile 3. **โณ TODO**: Add WhatsApp OTP setup UI to Profile 4. **โณ TODO**: Add WhatsApp tab to OTP verification page 5. **โณ TODO**: Test complete flow 6. **โณ OPTIONAL**: Restore auth page design --- ## ๐ŸŽฏ **Quick Start - Next Steps:** 1. **Add WhatsApp OTP states** to Profile.tsx (already started) 2. **Add handlers** for phone update and WhatsApp OTP 3. **Add UI cards** for phone and WhatsApp OTP 4. **Update OTP verification page** to include WhatsApp tab 5. **Test end-to-end flow** --- ## ๐Ÿ“ **Files to Modify:** 1. โœ… `apps/api/src/auth/auth.service.ts` - Avatar fix DONE 2. โณ `apps/web/src/components/pages/Profile.tsx` - Add phone & WhatsApp UI 3. โณ `apps/web/src/components/pages/OtpVerification.tsx` - Add WhatsApp tab 4. โณ `apps/web/src/components/pages/Login.tsx` - Restore design (optional) 5. โณ `apps/web/src/components/pages/Register.tsx` - Restore design (optional) --- **Backend is 100% ready. Frontend integration is straightforward - just add UI components!** ๐Ÿš€