This document provides a step-by-step guide to setting up your Firebase project and configuring it for use with the Driftboard application.
If you don't already have one, create a new Firebase project:
- Go to the Firebase Console.
- Click "Add project" or "Create a project".
- Follow the on-screen instructions to set up your project. You can enable Google Analytics if you wish.
For Driftboard to function, you need to enable two core Firebase services:
- In your Firebase project, navigate to Build > Authentication.
- Click "Get started".
- Go to the "Sign-in method" tab.
- Enable the "Email/Password" provider. This is the primary authentication method used by Driftboard.
- In your Firebase project, navigate to Build > Firestore Database.
- Click "Create database".
- Choose "Start in production mode" (we will set up security rules later).
- Select a Firestore location. Choose a region close to your users for optimal performance.
To connect your Next.js application to Firebase, you need to register it as a web app:
-
In your Firebase project overview, click the "Web" icon (</>) to "Add app to get started".
-
Register your app. You can give it a nickname (e.g., "Driftboard Web"). Hosting is not required for this step.
-
After registration, you will be presented with your Firebase configuration object. It will look something like this:
const firebaseConfig = { apiKey: "YOUR_API_KEY", authDomain: "YOUR_AUTH_DOMAIN", projectId: "YOUR_PROJECT_ID", storageBucket: "YOUR_STORAGE_BUCKET", messagingSenderId: "YOUR_MESSAGING_SENDER_ID", appId: "YOUR_APP_ID", };
Keep this configuration handy. You will need these values for your environment variables.
Driftboard uses environment variables to connect to your Firebase project. Create a .env.local file in the root of your project and add the following variables, replacing the placeholders with your actual Firebase configuration values:
NEXT_PUBLIC_FIREBASE_API_KEY="YOUR_API_KEY"
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN="YOUR_AUTH_DOMAIN"
NEXT_PUBLIC_FIREBASE_PROJECT_ID="YOUR_PROJECT_ID"
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET="YOUR_STORAGE_BUCKET"
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID="YOUR_MESSAGING_SENDER_ID"
NEXT_PUBLIC_FIREBASE_APP_ID="YOUR_APP_ID"
For administrative scripts (like data migrations or cleanup), you need a Firebase Service Account key. This grants the script administrative privileges to your Firestore database.
- In your Firebase project, navigate to Project settings (gear icon ⚙️).
- Go to the "Service accounts" tab.
- Click "Generate new private key". A JSON file will be downloaded.
- Rename this file to
serviceAccountKey.jsonand place it in thescripts/directory of your project. - IMPORTANT: Ensure
scripts/serviceAccountKey.jsonis added to your.gitignorefile to prevent committing private credentials.
Driftboard uses Firestore Security Rules and composite indexes defined as code. You need to deploy these to your Firebase project.
-
Ensure you have the Firebase CLI installed (
npm install -g firebase-tools). -
Log in to the Firebase CLI (
firebase login). -
Set your active Firebase project (
firebase use v0-driftboard-clone). -
Deploy the rules and indexes:
firebase deploy --only firestore:rules,firestore:indexes
Your Firebase project is now fully set up and configured for the Driftboard application!