Short answer: Yes, your repo can be public, but you should take some precautions.
-
User Data: All user data (books, profiles, etc.) is stored in Firestore and protected by Firebase Security Rules. The API key alone cannot access user data.
-
Firebase API Keys: Firebase API keys are designed to be public. They're included in client-side code and visible to anyone. Security comes from:
- Firestore Security Rules (which you've configured)
- API Key Restrictions (which you should set up - see below)
Even though API keys are public, you should restrict them to prevent abuse:
- Go to Google Cloud Console
- Select your Firebase project (
my-reads-52323) - Go to APIs & Services > Credentials
- Find your API key (
AIzaSyAkQsFGVLmB9M1IkWJsLt-dFLzYtRI3eWY) - Click Edit
- Under Application restrictions, select:
- HTTP referrers (web sites)
- Add your domains:
http://localhost:3000/*(for development)https://my-reads-blush.vercel.app/*(your production domain)https://*.vercel.app/*(if you use preview deployments)
- Under API restrictions, select:
- Restrict key
- Select only: Firebase Authentication API and Cloud Firestore API
- Click Save
This prevents others from using your API key on unauthorized domains or for unauthorized APIs.
The code now supports environment variables. Create a .env file (it's already in .gitignore):
cp .env.example .envThen fill in your Firebase config values. For production (Vercel), add these as environment variables in your Vercel project settings.
Make sure your Firestore security rules are properly configured. They should:
- β Allow users to read/write only their own data
- β Allow unauthenticated users to read public profiles only
- β Prevent unauthorized access to private data
If you're worried about the exposed API key, you can rotate it:
- Go to Firebase Console > Project Settings > General
- Scroll to "Your apps" > Web app
- Click the settings icon > Regenerate key
- Update your
.envfile and Vercel environment variables
Note: This won't remove the old key from git history, but it will invalidate it.
- β User passwords (handled by Firebase Auth)
- β GitHub OAuth secrets (stored in Firebase Console, not in code)
- β Google OAuth secrets (stored in Firebase Console, not in code)
- β Firestore data (protected by security rules)
- β User authentication tokens (managed by Firebase)
Your repo is safe to be public as long as:
- β Firestore security rules are properly configured (they are)
- β API key restrictions are set up (recommended)
- β No actual secrets are hardcoded (there aren't)
The Firebase API key being visible is normal and expected for client-side Firebase apps. The real security comes from your Firestore security rules, which you've already configured correctly.