State Management
Zustand Store
The app uses Zustand with localStorage persistence (lib/store.ts):
Store State Shape
Using Selectors
Access specific state slices to avoid unnecessary re-renders:Storage Key
All data persists under the localStorage key:ttai-app-store
Authentication
The template supports two authentication modes:1. Local User Auth (No Setup Required)
Simple auth for development or apps that donβt need full authentication:2. Firebase Auth (Google OAuth)
Full authentication with Firebase:AuthContext Provider
TheAuthContext wraps your app in app/layout.tsx:
Using Auth in Components
Protecting Routes
Use theAuthGuard component:
Firebase Setup
1
Create Firebase Project
Go to Firebase Console and create a new project.
2
Enable Authentication
Navigate to Authentication β Sign-in method and enable:
- Email/Password
3
Get Config
Go to Project Settings β General β Your apps β Web app.
Copy the configuration object.
4
Add Environment Variables
.env.local
Integrating Auth with ToughTongue
Pass user info to scenarios:Troubleshooting
Firebase: Error (auth/invalid-api-key)
Firebase: Error (auth/invalid-api-key)
Solution:
- Double-check all Firebase config values in
.env.local - Ensure all 6 Firebase variables are set
- Restart dev server after changes
Google Sign-In not working
Google Sign-In not working
Solution: - Verify Google provider is enabled in Firebase Console - Add your domain to
authorized domains in Firebase Console β Authentication β Settings - For localhost, it should be
authorized by default
Data not persisting
Data not persisting
Cause: Zustand store uses localStorage (per-browser, per-domain).Notes:
- Clearing browser data clears saved results
- Data doesnβt sync across browsers/devices
- For production, consider syncing to Firestore
Next Steps
Deployment
Deploy to production
API Reference
Full API documentation