Firebase Setup
From SCRUM-8: Create Firebase project
My Learning Notes
Firebase: BaaS (Backend as a Service), runs on Google Cloud, has JSON database that provides applications with data in real-time. It also has authentication service and provides REST endpoints for its database.
Authentication Flow
- Collect user input
- Call SDK methods to send to Firebase servers for validation
- Firebase sends back JWT token
- Token saved in header of each subsequent request
Firestore
- Data storage service
- Document/collection model
- SDK methods:
addDoc,getDoc, etc.
What is Firebase?
Firebase is a Backend-as-a-Service (BaaS) platform by Google. It provides:
- Authentication (Google, email, etc.)
- Firestore (NoSQL database)
- Hosting
- Cloud Functions
- And more...
Firebase has two databases:
- Realtime Database (older)
- Firestore (newer) - this is what VocabPal uses
Why Firebase for VocabPal?
- No server needed - Backend is managed for you
- Real-time sync - Changes sync instantly across devices
- Easy auth - Google sign-in with a few lines of code
- Free tier - Generous free usage for learning
Setting Up Firebase
1. Create Project
- Go to Firebase Console
- Click "Add Project"
- Name it (e.g., "vocabpal-learning")
- Disable Google Analytics (optional for learning)
2. Enable Authentication
- Firebase Console → Authentication → Sign-in method
- Enable Google provider
3. Create Firestore Database
- Firebase Console → Firestore Database
- Create database
- Start in test mode (for development)
4. Register Web App
- Click the web icon
</> - Register app name
- Copy the config object
- Save config values to
.envfile
5. Initialize in Code
// shared/src/services/config.ts
import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';
import { getFirestore } from 'firebase/firestore';
const firebaseConfig = {
apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN,
projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID,
storageBucket: import.meta.env.VITE_FIREBASE_STORAGE_BUCKET,
messagingSenderId: import.meta.env.VITE_FIREBASE_MESSAGING_SENDER_ID,
appId: import.meta.env.VITE_FIREBASE_APP_ID,
};
const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);
export const db = getFirestore(app);
The import.meta.env TypeScript Error
When using Vite with TypeScript, you'll get an error on import.meta.env because TypeScript doesn't know about Vite's environment variables.
Solution: Create a type declaration file:
// vite-env.d.ts
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_FIREBASE_API_KEY: string;
readonly VITE_FIREBASE_AUTH_DOMAIN: string;
readonly VITE_FIREBASE_PROJECT_ID: string;
readonly VITE_FIREBASE_STORAGE_BUCKET: string;
readonly VITE_FIREBASE_MESSAGING_SENDER_ID: string;
readonly VITE_FIREBASE_APP_ID: string;
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}
When TypeScript gives you errors about something that "should work", it often means you need a type declaration file (.d.ts). Google "[thing] typescript types" to find solutions.
Security Note
Never commit Firebase config to public repos! Use environment variables:
# .env (add to .gitignore!)
VITE_FIREBASE_API_KEY=AIza...
VITE_FIREBASE_AUTH_DOMAIN=vocabpal-learning.firebaseapp.com
# ... etc
Code Review Feedback
Katie Nguyen (2026-02-03):
**[Code Review Feedback] **Great summary! You nailed the key concepts: Firebase as BaaS on Google Cloud, authentication flow with JWT tokens, and Firestore document/collection model with SDK methods (addDoc, getDoc). One small note: Firebase also has Realtime Database (older) which is different from Firestore (newer). We are using Firestore for VocabPal. Approved!
Key Takeaways
- Firebase = BaaS on Google Cloud
- Auth uses JWT tokens
- Firestore uses document/collection model
- Use
.envfor config values (security!) - Create
vite-env.d.tsto fix TypeScript errors