Firebase Services Overview
MissΓ£o uses the following Firebase services:
Authentication
Email/Password, Google Sign-In, and Apple Sign-In for user authentication.
Cloud Firestore
NoSQL database for storing users, parishes, events, and admin data.
Cloud Storage
File storage for images (parish photos, user avatars, event images).
Cloud Functions
Server-side logic for admin operations, notifications, and data processing.
Cloud Messaging (FCM)
Push notifications for iOS, Android, and Web platforms.
Firebase Hosting
Web hosting for the Admin Panel and Widgetbook documentation.
π° Firebase Billing Information
Cloud Functions require the Firebase Blaze (pay-as-you-go) plan. You cannot deploy functions on the free Spark plan.
Firebase charges based on usage (reads, writes, function invocations, storage, bandwidth). Small apps typically stay within free tier limits.
All Firebase costs are your responsibility. We strongly recommend setting up budget alerts in Google Cloud Console.
Step 1: Create a Firebase Project
- Go to Firebase Console
- Click "Add project" or "Create a project"
- Enter your project name (e.g., "my-church-app")
- Accept the terms and continue
- Enable or disable Google Analytics (recommended: enable)
- If enabling Analytics, select or create a Google Analytics account
- Click "Create project"
Step 2: Enable Authentication
- In Firebase Console, go to Build β Authentication
- Click "Get started"
- Enable the following sign-in providers:
Email/Password
- Click on "Email/Password"
- Toggle "Enable" to ON
- Optionally enable "Email link (passwordless sign-in)"
- Click "Save"
Google Sign-In
- Click on "Google"
- Toggle "Enable" to ON
- Add a support email address
- Click "Save"
Apple Sign-In (for iOS)
- Click on "Apple"
- Toggle "Enable" to ON
- Configure your Apple Developer credentials:
- Services ID
- Apple Team ID
- Key ID and Private Key
- Click "Save"
Step 3: Set Up Firestore Database
- Go to Build β Firestore Database
- Click "Create database"
- Choose "Start in production mode"
- Select your database location:
- Brazil:
southamerica-east1(SΓ£o Paulo) - US:
us-central1 - Europe:
europe-west1
- Brazil:
- Click "Enable"
Deploy Security Rules
The project includes pre-configured security rules. Deploy them with:
firebase deploy --only firestore:rules
Firestore Collections Structure
| Collection | Description |
|---|---|
users |
User profiles and preferences |
parishes |
Parish information and details |
events |
Parish events and schedules |
admins |
Admin panel users and roles |
notifications |
Push notification records |
mail |
Email queue (for Trigger Email extension) |
Step 4: Set Up Cloud Storage
- Go to Build β Storage
- Click "Get started"
- Choose "Start in production mode"
- Select the same location as your Firestore database
- Click "Done"
Deploy Storage Rules
firebase deploy --only storage
Storage Structure
gs://your-project.appspot.com/
βββ parishes/
β βββ {parishId}/
β βββ photos/ # Parish photos
β βββ logo/ # Parish logo
βββ users/
β βββ {userId}/
β βββ avatar/ # User profile picture
βββ events/
βββ {eventId}/
βββ images/ # Event images
Step 5: Deploy Cloud Functions
Upgrade to Blaze Plan
Cloud Functions require the Blaze (pay-as-you-go) plan:
- Click the βοΈ gear icon in the Firebase Console
- Select "Usage and billing"
- Click "Modify plan"
- Select "Blaze" and add a billing account
Deploy Functions
# Navigate to project root
cd ~/projects/missao
# Deploy all functions
firebase deploy --only functions
Available Cloud Functions
| Function | Type | Description |
|---|---|---|
validateAdminAccess |
Callable | Validates admin authentication and role |
inviteAdmin |
Callable | Creates new admin invitation |
updateAdminRole |
Callable | Updates admin permissions |
revokeAdminAccess |
Callable | Deactivates admin account |
getAdminsPaginated |
Callable | Lists admins with pagination |
getDashboardMetrics |
Callable | Dashboard statistics |
sendPushNotification |
Callable | Sends push notifications |
Step 6: Configure Cloud Messaging (FCM)
iOS Configuration
- Generate an APNs key in Apple Developer Console
- Go to Firebase Console β Project Settings β Cloud Messaging
- Under "Apple app configuration", upload your APNs key
Android Configuration
Android is configured automatically when you add google-services.json to your project.
Web Configuration
Generate a VAPID key for web push notifications:
- Go to Project Settings β Cloud Messaging
- Under "Web configuration", click "Generate key pair"
- Copy the key and add it to your environment configuration
Step 7: Set Up Firebase Hosting
Configure hosting targets for the Admin Panel:
# Add hosting target for admin panel
firebase target:apply hosting admin YOUR_PROJECT_ID
# Deploy (after building)
flutter build web --dart-define-from-file=.env.prod
firebase deploy --only hosting:admin
The firebase.json already includes the hosting configuration with:
- SPA rewrites (all routes β index.html)
- Cache headers for assets
- Hosting targets for admin and widgetbook
Step 8: Install Extensions (Optional)
Trigger Email Extension
For sending emails (admin invitations, password resets):
- Go to Extensions in Firebase Console
- Search for "Trigger Email"
- Click "Install"
- Configure with your SMTP provider (SendGrid recommended):
SMTP_CONNECTION_URI=smtps://apikey:YOUR_API_KEY@smtp.sendgrid.net:465 MAIL_COLLECTION=mail DEFAULT_FROM=noreply@yourdomain.com
Step 9: Configure FlutterFire
Run FlutterFire CLI to generate platform configurations:
# Ensure FlutterFire CLI is installed
dart pub global activate flutterfire_cli
# Configure Firebase
flutterfire configure --project=YOUR_PROJECT_ID
This generates:
lib/firebase_options.dart- Dart configurationandroid/app/google-services.json- Android configurationios/Runner/GoogleService-Info.plist- iOS configuration
Step 10: Create First Admin User
After deploying Cloud Functions, create your first admin:
Option 1: Using Firebase Console
- Go to Authentication β Users
- Add a new user with email/password
- Go to Firestore β admins collection
- Create a document with the user's UID:
{
"uid": "USER_UID_HERE",
"email": "admin@example.com",
"displayName": "Super Admin",
"role": "super_admin",
"status": "active",
"createdAt": Timestamp,
"createdBy": "system"
}
Option 2: Using Firebase CLI
# This requires a custom script (included in functions/scripts/)
node functions/scripts/create-admin.js --email=admin@example.com --role=super_admin
Firebase Emulators (Development)
For local development, use Firebase Emulators:
# Start all emulators
firebase emulators:start
# Start specific emulators
firebase emulators:start --only auth,firestore,functions
Emulator ports (configured in firebase.json):
| Service | Port | URL |
|---|---|---|
| Auth | 9099 | http://localhost:9099 |
| Firestore | 8080 | http://localhost:8080 |
| Functions | 5001 | http://localhost:5001 |
| Storage | 9199 | http://localhost:9199 |
| Hosting | 5000 | http://localhost:5000 |
| Emulator UI | 4002 | http://localhost:4002 |
Next Steps
With Firebase configured, proceed to:
- Configuration - Set up environment variables and API keys
- Deployment - Deploy to production