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:

firebase deploy --only firestore
🔒 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:

firebase deploy --only firestore:indexes
📊 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:

firebase deploy --only storage
📁 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:

🔧 Deploy Cloud Functions

Deploy all cloud functions using Firebase CLI:

firebase deploy --only functions
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
2. Payment Gateway Functions
3. Email & Authentication Functions
4. User Management Functions
5. Utility Functions
⚙️ Configuration Requirements

Before deploying, ensure these configurations are set:

🔗 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
💡 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:

https://YOUR_REGION-YOUR_PROJECT_ID.cloudfunctions.net/razorpayFeeWebhook

Example: https://us-central1-aerokites-edu.cloudfunctions.net/razorpayFeeWebhook

How to Create in Razorpay Dashboard:
  1. Login to your Razorpay Dashboard
  2. Go to SettingsWebhooks
  3. Click Add New Webhook
  4. Enter the webhook URL from above
  5. Select Eventspayment.captured
  6. Click Create Webhook
  7. Copy the Webhook Secret - you'll need this for the app settings
🔗 Step 3: Create Stripe Webhook

Webhook URL Format:

https://YOUR_REGION-YOUR_PROJECT_ID.cloudfunctions.net/stripeFeeWebhook

Example: https://us-central1-aerokites-edu.cloudfunctions.net/stripeFeeWebhook

How to Create in Stripe Dashboard:
  1. Login to your Stripe Dashboard
  2. Go to DevelopersWebhooks
  3. Click Add endpoint
  4. Enter the webhook URL from above
  5. Select Events to sendcheckout.session.completed
  6. Click Add endpoint
  7. 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)
B. Stripe Settings (App Settings → Payment Gateway → Stripe)
💡 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:

// Replace all instances of: "your-email@gmail.com" // With: "YOUR_EMAIL@gmail.com"
Noreply Email Address:

Replace the noreply email address with your own domain.

Files to Update:

// Replace: from: 'Aerokites Edu ', // With: from: 'Your School Name ',
📧 Email Template Customization
Email Templates to Update:
  1. 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
  2. Custom Email Function (Lines 1110, 1125, 1130)
    • Purpose: General email sending functionality
    • Customization: Update default sender email and name
  3. 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:

// Replace SMTP configuration: user: "your-email@gmail.com", pass: "your_app_password-not_regular_password", // With: user: "YOUR_EMAIL@gmail.com", pass: "YOUR_APP_PASSWORD",
🎨 Branding Customization
School Name and Branding:

Replace "Aerokites Edu" with your school name throughout the email templates.

Files to Update:

// Replace: let fromName = 'Aerokites Edu'; from: 'Aerokites Edu ', // With: let fromName = 'YOUR_SCHOOL_NAME'; from: 'YOUR_SCHOOL_NAME ',
Email Footer:

Update the email footer with your school information.

Files to Update:

// Replace: YOUR_SCHOOL_NAME
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:

// Replace the hardcoded Firebase project configuration: projectId: 'aerokites-edu', storageBucket: 'aerokites-edu.firebasestorage.app' // With: projectId: 'YOUR_ACTUAL_PROJECT_ID', storageBucket: 'YOUR_ACTUAL_PROJECT_ID.firebasestorage.app' // Replace webhook secrets: let WEBHOOK_SECRET = "YOUR_WEBHOOK_SECRET"; let STRIPE_FEE_WEBHOOK_SECRET = "YOUR_STRIPE_FEE_WEBHOOK_SECRET"; // With: let WEBHOOK_SECRET = "YOUR_ACTUAL_WEBHOOK_SECRET"; let STRIPE_FEE_WEBHOOK_SECRET = "YOUR_ACTUAL_STRIPE_WEBHOOK_SECRET";
📊 Summary of Changes Required
Total Files to Update: 1
Types of Changes:
  1. SMTP User Credentials (Lines 164, 196, 212)
  2. Email Sender Addresses (Lines 1110, 1355)
  3. Company Information (Line 1365)
  4. School Branding (Lines 1115, 1355)
  5. Project Configuration (Lines 190, 191)
Purpose of Each Email Function:
⚠️ 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