Configure Firebase Authentication, Firestore, and Admin SDK for the Argument Analysis Tool
The Argument Analysis Tool uses Firebase for authentication and data storage. This guide covers the complete setup process for both client-side and server-side Firebase integration.
The values in the config file are project-specific and should be obtained from your Firebase Console. These values are safe to commit to version control as they identify your Firebase project but don’t provide privileged access.
The application uses a smart initialization strategy that supports both development and production environments:
// src/firebase/index.tsimport { firebaseConfig } from '@/firebase/config';import { initializeApp, getApps, getApp, FirebaseApp } from 'firebase/app';import { getAuth } from 'firebase/auth';import { getFirestore } from 'firebase/firestore';export function initializeFirebase() { if (!getApps().length) { let firebaseApp; try { // Attempt to initialize via Firebase App Hosting environment variables firebaseApp = initializeApp(); } catch (e) { // Fallback to firebase config object for development if (process.env.NODE_ENV === "production") { console.warn('Automatic initialization failed. Falling back to config.', e); } firebaseApp = initializeApp(firebaseConfig); } return getSdks(firebaseApp); } return getSdks(getApp());}export function getSdks(firebaseApp: FirebaseApp) { return { firebaseApp, auth: getAuth(firebaseApp), firestore: getFirestore(firebaseApp) };}
Why Two Initialization Paths?
Firebase App Hosting Integration: When deployed to Firebase App Hosting, the platform automatically injects environment variables that configure Firebase. Calling initializeApp() without arguments allows Firebase to auto-configure.Development Fallback: In local development, these environment variables aren’t available, so the app falls back to the firebaseConfig object defined in config.ts.This dual approach enables:
Zero-configuration production deployments
Seamless local development
No manual environment variable management for Firebase config
Never commit .env.local to version control! The private key provides full admin access to your Firebase project. Add .env.local to your .gitignore file.
The application also requires API keys for external services:
# Google AI (Genkit)GOOGLE_API_KEY="your-google-ai-api-key"# Web Search (SerpAPI)SERPAPI_API_KEY="your-serpapi-key"# Social Media Search (Twitter/X)TWITTER_BEARER_TOKEN="your-twitter-bearer-token"
# Firebase Admin SDK (Required)SERVICE_ACCOUNT_PROJECT_ID="..."SERVICE_ACCOUNT_CLIENT_EMAIL="..."SERVICE_ACCOUNT_PRIVATE_KEY="..."# Google AI (Required)GOOGLE_API_KEY="..."# External Services (Optional but recommended)SERPAPI_API_KEY="..." # For web searchTWITTER_BEARER_TOKEN="..." # For social pulse
The application will function without SERPAPI_API_KEY and TWITTER_BEARER_TOKEN, but the argument analysis will be less comprehensive without web search and social media insights.