Overview
Argument Cartographer uses Firebase for authentication and data persistence. This guide walks you through setting up Firebase with the strict security model implemented in the application.Create Firebase Project
Create New Project
- Go to Firebase Console
- Click “Add project”
- Enter project name (e.g., “argument-cartographer”)
- Enable Google Analytics (optional)
- Click “Create project”
Register Web App
- In Firebase Console, click “Add app” → Web
- Register app nickname (e.g., “Argument Cartographer Web”)
- Check “Also set up Firebase Hosting” (optional)
- Click “Register app”
- Copy the Firebase configuration values
Configure Firebase Authentication
Enable Sign-in Methods
Enable the authentication providers you want to support:Recommended providers:
- Email/Password: Basic authentication
- Google: OAuth sign-in
- Anonymous: Guest access (optional)
The application’s security rules work with any Firebase authentication provider.
Set Up Firestore Database
Create Firestore Database
- Go to Build → Firestore Database
- Click “Create database”
- Select location (choose closest to your users)
- Start in Production mode (we’ll add security rules next)
Deploy Security Rules
The application uses a strict user-ownership model. Deploy these security rules:Navigate to Firestore Database → Rules and paste the following:Click “Publish” to deploy the rules.
firestore.rules
Security Model Deep Dive
Core Philosophy
The application implements a strict user-ownership model based on these principles:Default Deny
Default Deny
All operations are denied unless explicitly allowed. There is no public data.
Path-Based Authorization
Path-Based Authorization
Denormalized User IDs
Denormalized User IDs
Documents include a
userId field that’s validated on creation and immutable:No User Scraping
No User Scraping
Listing the
/users collection is explicitly forbidden:Data Structure
All user data is organized hierarchically:Permission Error Handling
The application includes custom error handling for permission denials:Generate Service Account Key
For server-side operations (admin SDK), generate a service account key:Navigate to Service Accounts
In Firebase Console:
- Go to Project Settings (gear icon)
- Select Service accounts tab
Generate Private Key
- Click “Generate new private key”
- Click “Generate key” in the confirmation dialog
- Save the JSON file securely (never commit to version control)
Configure Firestore Indexes
For optimal query performance, create composite indexes:Testing Firebase Integration
Verify your Firebase setup:Monitoring and Maintenance
Monitor Usage
Monitor Usage
Firebase Console → Usage and billingTrack:
- Firestore reads/writes/deletes
- Authentication sign-ins
- Storage usage
- Network egress
Firebase free tier includes:
- 50K reads/day
- 20K writes/day
- 1GB storage
Backup Strategy
Backup Strategy
Automated backups:
- Go to Firestore Database → Data → Backups
- Enable Automatic backups
- Configure retention period (7-365 days)
Security Auditing
Security Auditing
Regularly review:
- Authentication → Users - Check for suspicious accounts
- Firestore → Rules - Review rule changes
- Usage → Logs - Monitor denied requests
- Unusual spike in denied requests (possible attack)
- High authentication failures
- Quota approaching limits
Upgrade to Blaze Plan
For production deployments, consider upgrading to the Blaze (pay-as-you-go) plan: Benefits:- Increased quotas for high-traffic apps
- Access to Firebase Extensions
- Cloud Functions integration
- Better SLA and support
- Exceeding free tier limits
- Need cloud functions for background processing
- Production app with revenue
Troubleshooting
Permission denied errors
Permission denied errors
Symptoms:
Missing or insufficient permissions errorSolutions:- Verify user is authenticated (
request.auth != null) - Check
userIdin path matchesrequest.auth.uid - Ensure document has required
userIdfield - Review security rules deployment status
Service account authentication failing
Service account authentication failing
Check:
- Private key format (escaped newlines:
\n) - Key is wrapped in quotes
- Client email is correct
- Project ID matches
- Service account has required permissions
Indexes missing
Indexes missing
Symptoms: Query fails with “index required” errorSolution:
- Click the link in the error message
- Firebase will create the index automatically
- Wait 2-5 minutes for index to build
- Retry the query
Next Steps
Environment Variables
Configure all required environment variables
Deploy to Vercel
Deploy your application to production
Common Issues
Troubleshoot deployment problems
Performance
Optimize Firebase performance
