npm install -g firebase-tools
firebase loginfirebase init firestore
# Select your Firebase project
# Accept default firestore.rules and firestore.indexes.jsonfirebase deploy --only firestore:rules
firebase deploy --only firestore:indexesCreate .env.local in the frontend directory:
NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key_here
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_idGet these values from:
- Firebase Console → Project Settings → General → Your apps → Web app
import MarketComments from '@/components/MarketComments';
function MarketPage() {
const marketId = 123;
const walletAddress = "GAXYZ..."; // or null if not connected
return (
<div>
{/* Your market content */}
<MarketComments
marketId={marketId}
walletAddress={walletAddress}
/>
</div>
);
}# Start your Next.js app
cd frontend
npm run dev
# Open in two browsers
# Browser 1: http://localhost:3000
# Browser 2: http://localhost:3000 (incognito)
# Post a comment in Browser 1
# Watch it appear instantly in Browser 2!npm install --save-dev @firebase/rules-unit-testingfirebase emulators:start --only firestorenpm test -- --config jest.firestore.config.jsExpected output:
Test Suites: 1 passed, 1 total
Tests: 27 passed, 27 total
Coverage: 95%+
Solution: Deploy security rules
firebase deploy --only firestore:rulesSolution: Deploy indexes
firebase deploy --only firestore:indexesOr create manually in Firebase Console:
- Go to Firestore → Indexes
- Create composite index:
- Collection:
marketComments - Fields:
marketId(Ascending),createdAt(Descending)
- Collection:
Solution: Check Firebase configuration
- Verify environment variables in
.env.local - Check browser console for errors
- Ensure Firestore is enabled in Firebase Console
Solution: Check import
import { db } from '@/lib/firebase';Ensure firebase.ts exports db:
export { app, db, messaging, getToken, onMessage };- Go to Firebase Console → Firestore Database
- You should see
marketCommentscollection after first comment - Click on a document to see the structure
- Go to Firebase Console → Firestore Database → Rules
- You should see the deployed rules
- Click "Publish" if they're not active
- Go to Firebase Console → Firestore Database → Indexes
- You should see the composite index
- Status should be "Enabled" (may take a few minutes)
- Firebase CLI installed
- Security rules deployed
- Indexes created
- Environment variables set
- Component imported
- App running
- Can post comment
- Comment appears in Firestore Console
- Real-time sync works across browsers
- Pagination works
- Read
FIRESTORE_COMMENTS_README.mdfor detailed documentation - Review
firestore.rulesto understand security - Check
firestore.test.rulesfor test examples - Customize styling in
MarketComments.tsx - Add to your market detail pages
- Documentation: See
FIRESTORE_COMMENTS_README.md - Security Rules: See
firestore.ruleswith comments - Tests: See
firestore.test.rulesfor examples - Firebase Docs: https://firebase.google.com/docs/firestore
-
Development: Use Firestore emulator for local testing
firebase emulators:start --only firestore
-
Production: Set up billing alerts in Firebase Console
-
Monitoring: Enable Firestore monitoring in Firebase Console
-
Backup: Set up automated backups in Firebase Console
-
Security: Review security rules regularly
Setup Time: ~5 minutes
Difficulty: Easy
Prerequisites: Firebase project, Node.js installed