# Complete Firebase Authentication Setup Guide This document describes how to activate live authentication for the CRE Innovations Studio application using the Firebase Console. All client and server code, security headers, CSRF protections, and session cookies are already fully implemented and waiting for your credentials. --- ## 1. Firebase Project Setup 1. Open the [Firebase Console](https://console.firebase.google.com/). 2. Select your existing project or click **Add project** (e.g. `cre-innovations-studio`). --- ## 2. Enable Authentication Providers 1. In the Firebase Console left sidebar, navigate to **Build** > **Authentication**. 2. Click **Get Started** if Authentication is not yet activated. 3. In the **Sign-in method** tab: - **Google**: - Click **Google**, toggle **Enable**. - Choose your Project support email from the dropdown. - Click **Save**. - **Email/Password**: - Click **Email/Password**, toggle **Enable** (keep Email link disabled unless needed). - Click **Save**. --- ## 3. Whitelist Authorized Domains 1. Under **Authentication** > **Settings** tab > **Authorized domains**: - Verify `localhost` is listed (present by default for local development). - Click **Add domain** and enter your production domain (e.g. `your-domain.com`, `creinnovations.com`, or your deployment domain). --- ## 4. Get Client Web SDK Keys 1. Go to **Project Settings** (gear icon in the top left) > **General** tab. 2. Scroll down to the **Your apps** card: - If you haven't created a Web app yet, click the Web icon ``. - Register app with name (e.g. `CRE Studio Web`). 3. Under **SDK setup and configuration**, select **Config**. 4. Copy the values into your `.env.local` file: ```env NEXT_PUBLIC_FIREBASE_API_KEY=AIzaSy... NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project-id.firebaseapp.com NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project-id NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your-project-id.appspot.com NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789012 NEXT_PUBLIC_FIREBASE_APP_ID=1:123456789012:web:abcdef123456 NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=G-XXXXXXXXXX ``` --- ## 5. Get Server Admin SDK Keys (Zero-Loophole Security) To cryptographically mint secure `httpOnly` session cookies that cannot be accessed by browser scripts (XSS protection): 1. In **Project Settings**, switch to the **Service accounts** tab. 2. Ensure **Firebase Admin SDK** is selected (Node.js). 3. Click **Generate new private key** and confirm. A JSON file will download. 4. Open the downloaded JSON file and copy the values into `.env.local`: ```env FIREBASE_PROJECT_ID=your-project-id FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxxxx@your-project-id.iam.gserviceaccount.com FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC...\n-----END PRIVATE KEY-----\n" ``` > **Note:** The private key must include the surrounding quotes and newline `\n` characters as formatted in the JSON download. --- ## 6. Restart Server Once your `.env.local` file is populated: ```bash npm run dev # or npm run build && npm run start ``` The authentication system will immediately activate in full production mode!