This guide will walk you through setting up Firebase for authentication, document storage, and session management in your DocuMind application.
- A Google account
- Node.js and npm installed
- Basic knowledge of Firebase
- Go to Firebase Console
- Click "Create a project" or "Add project"
- Enter a project name (e.g., "documind-ai")
- Choose whether to enable Google Analytics (recommended)
- Click "Create project"
- In your Firebase project, go to "Authentication" in the left sidebar
- Click "Get started"
- Go to the "Sign-in method" tab
- Enable the following providers:
- Click "Email/Password"
- Toggle "Enable" to ON
- Toggle "Email link (passwordless sign-in)" if desired
- Click "Save"
- Click "Google"
- Toggle "Enable" to ON
- Add your authorized domain (localhost for development)
- Click "Save"
- GitHub
- Apple
- Go to "Firestore Database" in the left sidebar
- Click "Create database"
- Choose "Start in test mode" for development (you'll update security rules later)
- Select a location closest to your users
- Click "Done"
- Go to "Storage" in the left sidebar
- Click "Get started"
- Choose "Start in test mode" for development
- Select a location (same as Firestore)
- Click "Done"
- In your Firebase project, click the gear icon next to "Project Overview"
- Select "Project settings"
- Scroll down to "Your apps" section
- Click the web icon (</>)
- Enter an app nickname (e.g., "DocuMind Web")
- Click "Register app"
- Copy the Firebase configuration object
- Copy your Firebase config to
frontend/env.local:
# Firebase Configuration
NEXT_PUBLIC_FIREBASE_API_KEY=your_firebase_api_key_here
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- Replace the placeholder values with your actual Firebase configuration
- Copy the contents of
firestore.rules - In Firebase Console, go to "Firestore Database" → "Rules"
- Replace the existing rules with the copied content
- Click "Publish"
- Copy the contents of
storage.rules - In Firebase Console, go to "Storage" → "Rules"
- Replace the existing rules with the copied content
- Click "Publish"
For enhanced user management, you can set up Cloud Functions:
- Go to "Functions" in Firebase Console
- Click "Get started"
- Install Firebase CLI:
npm install -g firebase-tools - Login:
firebase login - Initialize:
firebase init functions - Deploy:
firebase deploy --only functions
- Go to "Authentication" → "Settings"
- Configure the following:
- Add your production domain
- Keep
localhostfor development
- Enable "Prevent abuse" if desired
- Configure password strength requirements
- Customize email templates for verification, password reset, etc.
- Go to "Firestore Database" → "Indexes"
- Create composite indexes for queries that use multiple fields
- Common indexes for DocuMind:
- Collection:
documents, Fields:uid(Ascending),uploadedAt(Descending) - Collection:
documents, Fields:uid(Ascending),category(Ascending)
- Collection:
- Start your development server:
npm run dev - Try to sign up with a new account
- Verify the user appears in Firebase Console → Authentication → Users
- Check that user profile is created in Firestore → users collection
- Test file upload to verify Storage is working
- Update security rules to remove test mode
- Set up proper domain restrictions
- Configure backup and monitoring
- Set up Firebase App Check for additional security
- Enable email verification
- Implement rate limiting
- Use strong password policies
- Enable multi-factor authentication for admin users
- Always validate user permissions
- Use security rules to enforce access control
- Implement proper input validation
- Log security events
- Limit file types and sizes
- Scan uploaded files for malware
- Implement proper access controls
- Use signed URLs for temporary access
-
Authentication not working
- Check domain is authorized
- Verify API keys are correct
- Check browser console for errors
-
Storage uploads failing
- Verify storage rules are correct
- Check file size limits
- Ensure file types are allowed
-
Firestore access denied
- Verify security rules are deployed
- Check user authentication status
- Ensure proper collection/document structure
Enable debug mode in your Firebase config:
// In firebaseConfig.ts
if (process.env.NODE_ENV === 'development') {
console.log('Firebase config:', firebaseConfig)
}- Firebase Analytics: Track user engagement and app performance
- Crashlytics: Monitor app crashes and errors
- Performance Monitoring: Track app performance metrics
- Remote Config: Manage app configuration remotely
- Firestore: Use appropriate read/write operations
- Storage: Implement file compression and cleanup
- Functions: Optimize function execution time
- Bandwidth: Use CDN for static assets
After completing this setup:
- Implement user roles and permissions
- Add advanced security features
- Set up monitoring and alerting
- Implement backup and disaster recovery
- Add performance optimization features
Note: Keep your Firebase configuration secure and never commit API keys to version control. Use environment variables and proper security practices in production.