A Next.js chat application with Firebase authentication, user-specific chat storage, and theme support.
- User authentication (signup, login, logout)
- User-specific chat threads
- Theme support (light, dark, system)
- Real-time chat with AI using Google's Gemini model
npm install
- Create a Firebase project at https://console.firebase.google.com/
- Enable Authentication with Email/Password
- Create a Firestore database
- Register a web app in your Firebase project
- Create a
.env.local
file in the root directory with the following variables:
# Firebase configuration
NEXT_PUBLIC_FIREBASE_API_KEY=your-api-key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project-id.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project-id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your-project-id.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your-messaging-sender-id
NEXT_PUBLIC_FIREBASE_APP_ID=your-app-id
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=your-measurement-id
# Google AI API Key (for chat)
GOOGLE_API_KEY=your-google-api-key
npm run dev
Open http://localhost:3000 with your browser to see the result.
/app
- Next.js app router pages/components
- React components/auth
- Authentication components/assistant-ui
- Chat UI components/theme
- Theme components/ui
- UI components
/lib
- Utility functions/context
- React context providers/services
- Firebase services
Add these security rules to your Firestore database:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /threads/{threadId} {
allow read, write: if request.auth != null && request.auth.uid == resource.data.userId;
allow create: if request.auth != null && request.resource.data.userId == request.auth.uid;
}
}
}