A real-time chat application built with React and Firebase. Authenticated users can browse users, start or continue chats, send text messages, share images, and use emojis—all with live updates.
- Authentication — Sign up and log in with email and password (Firebase Auth).
- Real-time messaging — Send and receive messages instantly via Firestore listeners.
- Image sharing — Attach and upload images to Firebase Storage; share image URLs in chat.
- Emoji picker — Insert emojis into messages with a click-outside-to-close picker.
- Users & chats — Sidebar with tabs: browse all users or your existing chatrooms.
- Chat list — See last message and timestamp per chat; click to open a conversation.
- Responsive UI — Tailwind CSS and DaisyUI for layout and components.
- React 19 + TypeScript
- Vite — dev server and build
- React Router 7 — routing (public: login/register; private: home, chat)
- Firebase — Auth, Firestore, Storage
- Tailwind CSS 4 + DaisyUI
- React Hook Form + Zod — forms and validation
- Zustand — client state (e.g. active tab)
- Sonner — toasts
- Day.js — message timestamps
- emoji-picker-react — emoji picker
- Node.js 18+
- npm (or pnpm / yarn)
- A Firebase project with Auth, Firestore, and Storage enabled
git clone https://github.com/kirilldevm/nextjs-firebase-chat-app
cd react-firebase-realtime-chat-app
npm install- Create a project at Firebase Console.
- Enable Authentication (Email/Password sign-in).
- Create a Firestore database.
- Create a Storage bucket.
- Register a web app and copy the config object.
Put your Firebase config in src/lib/fitebase.ts (replace the existing firebaseConfig):
const firebaseConfig = {
apiKey: 'YOUR_API_KEY',
authDomain: 'YOUR_PROJECT.firebaseapp.com',
projectId: 'YOUR_PROJECT_ID',
storageBucket: 'YOUR_PROJECT.firebasestorage.app',
messagingSenderId: '...',
appId: '...',
};For production, use environment variables and avoid committing secrets.
npm run devOpen http://localhost:5173. Sign up, log in, then use the sidebar to switch between Users and Chats and open a conversation.
| Command | Description |
|---|---|
npm run dev |
Start Vite dev server |
npm run build |
TypeScript check + build |
npm run preview |
Preview production build |
npm run lint |
Run ESLint |
src/
├── components/ # UI (sidebar, chats, users, message-input, message-card, …)
├── hooks/ # useAuth, useSendMessage, useGetMessagesByChatroomId, …
├── layouts/ # PrivateLayout (auth required), PublicLayout (login/register)
├── lib/ # Firebase init (fitebase.ts)
├── pages/ # login, register, main-chat
├── schemas/ # Zod schemas (e.g. auth)
├── store/ # Zustand store
├── types/ # TypeScript types (user, message, chatroom)
├── App.tsx
├── main.tsx # Router + lazy-loaded pages
└── index.css # Tailwind + global styles
- Firestore:
chatrooms/{id}(metadata,users,usersData,lastMessage),chatrooms/{id}/messages(message docs). - Storage:
chatroom_images/for uploaded images; image URLs are stored in messageimageand inlastMessagewhen applicable.