This project uses environment variables to manage Firebase configuration. This prevents API keys from being committed to version control.
-
Copy the example environment file:
cp .env.example .env.local
-
Fill in your Firebase configuration values in
.env.local -
The
.env.localfile is gitignored and will never be committed
For the CI/CD pipeline to work, you must add the following secrets to your GitHub repository:
- Go to Settings → Secrets and variables → Actions
- Click New repository secret for each:
| Secret Name | Value |
|---|---|
VITE_FIREBASE_API_KEY |
Your Firebase API key |
VITE_FIREBASE_AUTH_DOMAIN |
your-project.firebaseapp.com |
VITE_FIREBASE_PROJECT_ID |
Your Firebase project ID |
VITE_FIREBASE_STORAGE_BUCKET |
your-project.firebasestorage.app |
VITE_FIREBASE_MESSAGING_SENDER_ID |
Your messaging sender ID |
VITE_FIREBASE_APP_ID |
Your Firebase app ID |
VITE_FIREBASE_MEASUREMENT_ID |
G-XXXXXXXXXX |
You can find these values in your Firebase Console: Project Settings → General → Your apps → SDK setup and configuration
Firebase API keys are different from typical API keys:
- They are NOT used to control access to backend resources
- They are safe to include in client-side code (per Firebase docs)
- Access control is handled by Firebase Security Rules and App Check
However, we still use environment variables to:
- Stop GitHub secret scanner alerts
- Allow different configs for dev/staging/prod
- Follow security best practices
Your Firestore rules should restrict access. Example:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Users can only access their own data
match /users/{userId}/{document=**} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
// Entries belong to users
match /entries/{entryId} {
allow read, write: if request.auth != null
&& request.auth.uid == resource.data.userId;
allow create: if request.auth != null
&& request.auth.uid == request.resource.data.userId;
}
}
}In Google Cloud Console:
- Go to APIs & Services → Credentials
- Click on your Firebase API key
- Under Application restrictions, select HTTP referrers
- Add your domains:
https://thelastaairbenderang.github.io/*http://localhost:*(for development)
App Check helps protect your backend from abuse:
- Enable App Check in Firebase Console
- Register your app with reCAPTCHA v3
- Enforce App Check in your Firebase services
If using password-based auth, consider tightening quotas:
- Go to Google Cloud Console → APIs & Services → Quotas
- Find
identitytoolkit.googleapis.com - Adjust rate limits to match expected traffic
If you believe your API key has been compromised:
- Firebase Console → Project Settings → General
- Scroll to your web app
- Click the menu (⋮) → Manage API key in Google Cloud Console
- Create a new key with proper restrictions
- Update your
.env.localand GitHub Secrets - Delete the old key
-
.env.localis in.gitignore - GitHub Secrets are configured for CI/CD
- Firebase Security Rules restrict data access
- API key is restricted to your domains
- (Optional) App Check is enabled
- No hardcoded credentials in source code