This project provides a secure, web-based admin dashboard to manage the maintenance mode of your application using Firebase Remote Config.
- Secure Login: Only whitelisted Google accounts can access the dashboard.
- Granular Control: Toggle maintenance mode globally, or specifically for Login/Dashboard screens.
- Custom Messages: Set custom titles and messages for maintenance screens.
- Audit Logging: Every configuration change is logged to Firestore with user and timestamp.
- Cost Effective: Uses Firebase Hosting and Cloud Functions (minimal cost within free tier limits, requires Blaze plan).
frontend/: React application (Vite + Tailwind CSS).functions/: Firebase Cloud Functions (Backend logic).
- Firebase Project: Create a project in the Firebase Console.
- Blaze Plan: Upgrade your project to the Blaze (Pay-as-you-go) plan to use Cloud Functions.
- Node.js: Install Node.js (v18 or later).
- Firebase CLI: Install globally via
npm install -g firebase-tools.
- Enable Authentication and set up the Google sign-in provider.
- Enable Cloud Firestore in production mode.
- Enable Remote Config.
- Enable Cloud Functions.
-
Clone the repository:
git clone <repo-url> cd <repo-name>
-
Set up Environment Variables: Create a
.envfile in thefrontend/directory with your Firebase config keys:VITE_FIREBASE_API_KEY=your_api_key VITE_FIREBASE_AUTH_DOMAIN=your_project_id.firebaseapp.com VITE_FIREBASE_PROJECT_ID=your_project_id VITE_FIREBASE_STORAGE_BUCKET=your_project_id.appspot.com VITE_FIREBASE_MESSAGING_SENDER_ID=your_sender_id VITE_FIREBASE_APP_ID=your_app_id -
Add Initial Whitelist User: Go to Firestore Console and create a collection named
whitelist. Add a document where the Document ID is your email address (e.g.,user@example.com). The fields can be empty or{ "role": "admin" }.
-
Login to Firebase:
firebase login firebase use --add
Select your project alias (e.g.,
default). -
Configure Hosting Target: This project is configured to deploy to a hosting target named
nudge. Run the following command to link this target to your Firebase Hosting site:firebase target:apply hosting nudge <your-hosting-site-name>
Replace
<your-hosting-site-name>with the site ID from your Firebase Console (Hosting tab). -
Deploy Everything: Run the following command from the root directory:
firebase deploy
This will automatically:
- Install frontend dependencies.
- Build the frontend application.
- Deploy:
- Firestore Security Rules
- Cloud Functions (
updateConfig) - Frontend to Firebase Hosting
- Open the hosted URL (provided by
firebase deploy). - Login with your Google account.
- If your email is whitelisted, you will see the dashboard.
- Modify the settings and click "Activate Configuration".
- View the audit history in the sidebar.
Frontend:
cd frontend
npm install
npm run devFunctions:
cd functions
npm install
npm run serveNote: To test functions locally with the frontend, you'll need to configure the emulator suite.
- Firestore Rules: Restrict read access to
whitelistandaudit_logsto authenticated users in the whitelist. - Cloud Functions: The
updateConfigfunction programmatically verifies the user is in the whitelist before applying changes.