Setup - Deploy Firebase Rules & Indexes (All Platforms)
🔒 Security & Performance Overview
This step deploys the pre-configured Firebase security rules and performance indexes that are essential for your app's security and optimal performance. The project includes ready-to-use configuration files that ensure proper data access control and efficient querying.
Step 10: Deploy Firebase Rules & Indexes
Your project includes pre-configured Firebase configuration files that provide enterprise-grade security and performance optimization. These files are located in the project root directory and can be deployed directly using Firebase CLI.
1Pre-configured Files Location
The following configuration files are included in your project root directory:
- 📜 firestore.rules
- 📜 firestore.indexes.json
- 📜 firebase_storage.rules
- 📜 cors.json
✅ Ready to Deploy:
These files are pre-configured with optimal security rules and performance indexes for AeroKites Edu. No manual configuration is required - you can deploy them directly.
2Deploy Firestore Security Rules
Deploy the pre-configured Firestore security rules to protect your database:
🔒 What These Rules Provide:
- User Authentication: Only authenticated users can access data
- Role-Based Access: Users can only access data relevant to their role
- Data Validation: Ensures data integrity and proper structure
- School Isolation: Users can only access their own school's data
3Deploy Firestore Composite Indexes
Deploy the pre-configured composite indexes for optimal query performance:
📊 What These Indexes Provide:
- Attendance Collection: Staff attendance by staffId and date
- Emails Collection: Efficient querying by recipients (array) and timestamp
- Homework Collection: Fast retrieval by class, section, and upload_date
- Leave Applications: Staff leave requests by staffId, status, and dates
- Notifications Collection: Quick access by userId and timestamp
- Salaries Collection: Staff salary records by staffId and creation date
- School Fee Invoices: Student fee management by school, status, and payment dates
- Subscription Invoices: School subscription management by status and dates
4Deploy Firebase Storage Rules
Deploy the pre-configured storage rules to secure file uploads:
📁 What These Rules Provide:
- File Upload Security: Only authenticated users can upload files
- File Type Validation: Restricts uploads to allowed file types
- Size Limits: Prevents oversized file uploads
- User Isolation: Users can only access their own uploaded files
5Verify Deployment Status
After deployment, verify that all rules and indexes are active:
A. Check Firestore Rules
Go to Firebase Console > Firestore Database > Rules to verify your security rules are active.
B. Check Firestore Indexes
Navigate to Firebase Console > Firestore Database > Indexes to see your composite indexes status.
C. Check Storage Rules
Go to Firebase Console > Storage > Rules to verify your storage security rules.
🎉 Deployment Complete!
Once all deployments are successful, your Firebase project will have enterprise-grade security and optimal performance. You can now proceed to the next setup steps.
🚀 Cloud Functions Deployment & Configuration
⚠️ CRITICAL: Cloud Functions Must Be Deployed
The functions/index.js
file contains essential backend logic that powers the entire application. Without deploying these functions, critical features will fail!
📋 Cloud Functions Overview
Your project includes comprehensive cloud functions that handle:
- Push Notifications (FCM) - Real-time notifications to users
- Payment Processing - Razorpay and Stripe integration
- Email Services - SMTP-based email delivery
- Authentication - Email OTP verification and user management
- User Management - Admin creation and user invitations
🔧 Deploy Cloud Functions
Deploy all cloud functions using Firebase CLI:
What Gets Deployed:
- 📜 Push Notification Service - FCM token management and notification delivery
- 📜 Payment Gateway Integration - Razorpay and Stripe webhook handlers
- 📜 Email Service - Custom email sending and SMTP management
- 📜 Authentication Functions - Email OTP verification and user cleanup
- 📜 User Management - Admin creation and invitation emails
- 📜 SMTP Testing - Connection testing and validation
📱 Cloud Functions Details
1. Push Notification Functions
firebaseFcm
- Main FCM endpoint for sending notifications- FCM Service - Token management and notification delivery
- Target-based notifications - All users, role-based, or school-specific
2. Payment Gateway Functions
razorpayFeeWebhook
- Razorpay fee payment webhook handlercreateStripeCheckoutSession
- Stripe checkout session creationstripeFeeWebhook
- Stripe fee payment webhook handler- Multi-currency support - Dynamic currency based on school settings
3. Email & Authentication Functions
sendCustomEmail
- Bulk and individual email sendingsendOtpEmail
- Email OTP generation and deliveryverifyOtp
- OTP verification and user authenticationcheckUserEmail
- Pre-verification email existence check
4. User Management Functions
sendSchoolAdminResetLink
- Admin account creation and setupsendParentInvitationEmail
- Parent invitation emailssendStaffInvitationEmail
- Staff invitation emailscleanupUnmappedAuthUser
- Automatic cleanup of unmapped users
5. Utility Functions
testSMTPConnection
- SMTP connection testingupdateUserEmail
- User email updates- Receipt generation - Custom receipt number generation
⚙️ Configuration Requirements
Before deploying, ensure these configurations are set:
- Node.js 18.x or higher - Required as specified in
functions/package.json
- Payment Gateway Settings - Razorpay and Stripe API keys
- SMTP Configuration - Email server settings
- Webhook Secrets - Payment gateway webhook verification
- FCM Configuration - Firebase Cloud Messaging setup
🔗 Payment Gateway Webhook URLs
CRITICAL: After deploying the functions/index.js
file (which contains all webhook logic functions), you must configure webhook URLs in your payment gateway dashboards for fee payments to work properly.
📍 Step 1: Get Your Firebase Project Region & ID
After deploying your cloud functions, you can easily find your project details from the Firebase Console:
A. Find Your Project ID & Region
- Go to Firebase Console
- Select your project
- In the left sidebar, click on Functions
- You'll see a list of deployed functions with their URLs
- All functions will show the same region and project ID in their URLs
💡 From the Image Example:
Looking at the Firebase Console Functions page, you can see:
- Project ID:
aerokites-edu
- Region:
us-central1
- Function URLs: All functions show
https://us-central1-aerokites-edu.cloudfunctions.net/[functionName]
🔗 Step 2: Create Razorpay Webhook
Webhook URL Format:
Example: https://us-central1-aerokites-edu.cloudfunctions.net/razorpayFeeWebhook
How to Create in Razorpay Dashboard:
- Login to your Razorpay Dashboard
- Go to Settings → Webhooks
- Click Add New Webhook
- Enter the webhook URL from above
- Select Events → payment.captured
- Click Create Webhook
- Copy the Webhook Secret - you'll need this for the app settings
🔗 Step 3: Create Stripe Webhook
Webhook URL Format:
Example: https://us-central1-aerokites-edu.cloudfunctions.net/stripeFeeWebhook
How to Create in Stripe Dashboard:
- Login to your Stripe Dashboard
- Go to Developers → Webhooks
- Click Add endpoint
- Enter the webhook URL from above
- Select Events to send → checkout.session.completed
- Click Add endpoint
- Copy the Signing secret - you'll need this for the app settings
✅ Webhook Configuration Complete
After creating webhooks in both dashboards, you'll have:
- ✅ Razorpay webhook URL and secret
- ✅ Stripe webhook URL and signing secret
- ✅ Both webhooks pointing to your Firebase Functions
⚙️ Step 4: Configure Payment Gateway Settings in App
Important: The following settings can be configured through the app's Settings screen, so you don't need to modify the functions/index.js
file:
A. Razorpay Settings (App Settings → Payment Gateway → Razorpay)
- Key ID - Your Razorpay public key
- Key Secret - Your Razorpay secret key
- Webhook Secret - The secret you copied from Razorpay dashboard
- Enable/Disable - Toggle Razorpay on/off
B. Stripe Settings (App Settings → Payment Gateway → Stripe)
- Secret Key - Your Stripe secret key
- Fee Webhook Secret - The signing secret you copied from Stripe dashboard
- Enable/Disable - Toggle Stripe on/off
💡 Configuration Method
Webhook URLs: Fixed in deployed cloud functions (cannot be changed via app settings)
Payment Gateway Settings: Configured through the app's Settings screen for easy management
Important: Both webhook URLs and payment gateway settings must be properly configured for payments to work
⚠️ Critical Webhook Security
- Webhook Secrets: Always use strong, unique secrets for each payment gateway
- HTTPS Only: Webhook URLs must use HTTPS (Firebase Functions automatically provide this)
- Signature Verification: The cloud functions automatically verify webhook signatures for security
- Test Mode: Use test webhook endpoints during development, switch to live endpoints for production
- Secret Management: Never expose webhook secrets in client-side code or public repositories
💡 Deployment Benefits
- Scalable Backend - Serverless functions that scale automatically
- Real-time Processing - Instant payment and notification handling
- Secure Operations - Server-side validation and security
- Multi-tenant Support - School-specific configurations
📧 Email Configuration Documentation for CodeCanyon Buyers
⚠️ CRITICAL: Email Configuration Required
The functions/index.js
file contains multiple email templates and SMTP configurations that need to be updated with your own email credentials and domain information before deployment.
📋 Overview
The Cloud Functions contain multiple email templates and SMTP configurations that need to be updated with your own email credentials and domain information.
🔧 Email Addresses to Replace
Primary Email Address:
Replace all occurrences of your-email@gmail.com
with your own email address.
Files to Update:
functions/index.js
(Lines 164, 196, 212, 1110, 1365)
Noreply Email Address:
Replace the noreply email address with your own domain.
Files to Update:
functions/index.js
(Line 1355)
📧 Email Template Customization
Email Templates to Update:
- SMTP Configuration (Lines 164, 196, 212)
- Purpose: Default SMTP settings for email delivery
- Customization: Update email and app password
- Note: Uses Gmail SMTP by default
- Custom Email Function (Lines 1110, 1125, 1130)
- Purpose: General email sending functionality
- Customization: Update default sender email and name
- OTP Email (Lines 1355, 1365)
- Purpose: Login verification codes
- Customization: Update sender email and company information
⚙️ SMTP Configuration
Default SMTP Settings:
The functions use default SMTP settings that need to be configured:
Files to Update:
functions/index.js
(Lines 164, 196, 212)
🎨 Branding Customization
School Name and Branding:
Replace "Aerokites Edu" with your school name throughout the email templates.
Files to Update:
functions/index.js
(Lines 1115, 1355)
Email Footer:
Update the email footer with your school information.
Files to Update:
functions/index.js
(Line 1365)
Email: your-email@gmail.com // With: YOUR_SCHOOL_NAME
Email: YOUR_EMAIL@gmail.com
🔧 Additional Configuration
Project Configuration:
Update Firebase project details. Webhook secrets are now dynamically loaded from Firestore settings.
Files to Update:
functions/index.js
(Lines 190, 191)
📊 Summary of Changes Required
Total Files to Update: 1
functions/index.js
- 8+ email-related configurations
Types of Changes:
- SMTP User Credentials (Lines 164, 196, 212)
- Email Sender Addresses (Lines 1110, 1355)
- Company Information (Line 1365)
- School Branding (Lines 1115, 1355)
- Project Configuration (Lines 190, 191)
Purpose of Each Email Function:
- ✅ SMTP Configuration - Email delivery settings
- ✅ Custom Email - General email sending
- ✅ OTP Verification - Login security codes
⚠️ Important Notes
- Use a real email address that you control
- Configure SMTP settings properly for email delivery
- Test email functionality after making changes
- Update school branding consistently across all templates
- Consider using a professional domain for noreply emails
- Configure payment gateway settings in Firestore for webhook processing