The Toolify frontend and backend are now properly integrated. Here's what was implemented:
- ✅ Added comprehensive error handling with custom
APIErrorclass - ✅ Added console logging for debugging API requests
- ✅ Improved type safety with
ChatResponseinterface - ✅ Better error messages for different HTTP status codes (401, 400, 500)
- ✅ Network error handling
- ✅ Improved authentication token handling
- ✅ User-friendly error messages displayed in chat
- ✅ Better error logging for debugging
- ✅ Graceful handling of authentication failures
- ✅ API URL defaults to production:
https://toolify-api.onrender.com - ✅ Can be overridden with
NEXT_PUBLIC_API_URLenvironment variable
Create .env.local in the frontend directory:
# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
CLERK_SECRET_KEY=your_clerk_secret_key
# Backend API URL (optional - defaults to production)
NEXT_PUBLIC_API_URL=https://toolify-api.onrender.comSet these environment variables in your Vercel project settings:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYCLERK_SECRET_KEYNEXT_PUBLIC_API_URL=https://toolify-api.onrender.com
- User signs in with Clerk (frontend)
- Clerk provides a JWT token
- Frontend sends token in
Authorization: Bearer <token>header - Backend validates token with Supabase Auth
- If valid, request is processed
- User types message in chat input
- Frontend calls
sendMessage()with auth token - Backend processes with Gemini AI
- Response returned and displayed in chat
- Chat history saved to Supabase
- User clicks paperclip icon and selects image
- Image sent to
/api/chatendpoint with message - Backend:
- Uploads image to Supabase Storage
- Uses Gemini Vision to recognize tool
- Performs Tavily research on tool
- Saves scan to database
- Response includes tool info, safety tips, YouTube links
- User clicks microphone button
- Browser records audio
- Audio blob sent to
/api/chatendpoint - Backend transcribes with Gemini
- Transcribed text processed as normal chat message
-
Text Chat
- Send a simple text message
- Verify AI responds appropriately
- Check message appears in chat history
-
Image Upload
- Upload image of a tool (hammer, drill, etc.)
- Verify tool is recognized
- Check response includes tool details and safety info
-
Voice Input
- Record a voice message
- Verify it's transcribed correctly
- Check AI responds to the transcription
-
Chat History
- Create multiple chats
- Verify they appear in sidebar
- Click on old chat to load history
-
Error Handling
- Test with invalid inputs
- Verify error messages are user-friendly
The integration includes extensive console logging:
- 🔗 API URL configuration
- 📤 Outgoing requests
- ✅ Successful responses
- ❌ Error details
Issue: "Authentication failed"
- Solution: Check Clerk keys are set correctly
- Verify Supabase is configured to accept Clerk tokens
Issue: "Network error"
- Solution: Check backend is running at
https://toolify-api.onrender.com - Verify CORS is configured correctly
Issue: "No response from AI"
- Solution: Check backend logs on Render
- Verify Gemini API key is valid
- Deploy Frontend: Push changes to Vercel
- Set Environment Variables: Configure in Vercel dashboard
- Test Production: Verify all features work on deployed site
- Monitor Logs: Check for any errors in first 24 hours
If you encounter issues:
- Check browser console for error messages
- Check backend logs on Render
- Verify all environment variables are set
- Test API endpoints directly at
/docs