3.1 KiB
3.1 KiB
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
- Open the Firebase Console.
- Select your existing project or click Add project (e.g.
cre-innovations-studio).
2. Enable Authentication Providers
- In the Firebase Console left sidebar, navigate to Build > Authentication.
- Click Get Started if Authentication is not yet activated.
- 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.
- Google:
3. Whitelist Authorized Domains
- Under Authentication > Settings tab > Authorized domains:
- Verify
localhostis 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).
- Verify
4. Get Client Web SDK Keys
- Go to Project Settings (gear icon in the top left) > General tab.
- 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).
- If you haven't created a Web app yet, click the Web icon
- Under SDK setup and configuration, select Config.
- Copy the values into your
.env.localfile:
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):
- In Project Settings, switch to the Service accounts tab.
- Ensure Firebase Admin SDK is selected (Node.js).
- Click Generate new private key and confirm. A JSON file will download.
- Open the downloaded JSON file and copy the values into
.env.local:
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_CLIENT_EMAIL=[email protected]
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC...\n-----END PRIVATE KEY-----\n"
Note: The private key must include the surrounding quotes and newline
\ncharacters as formatted in the JSON download.
6. Restart Server
Once your .env.local file is populated:
npm run dev # or npm run build && npm run start
The authentication system will immediately activate in full production mode!