Authentication or Database Error

The application could not connect to Google Cloud. This could be due to missing authentication credentials or an incomplete database setup in BigQuery.

Action Required for Deployed App

Most Likely Cause: Missing Environment Variable in Production

Your local environment works because it uses a `.env.local` file. This file is **not deployed**. You must set the `GCP_PROJECT` environment variable in your Firebase App Hosting backend configuration.

  1. Go to your Firebase Console and select your project.
  2. Navigate to the App Hosting section.
  3. Find your backend, click the three-dots menu, and select "Edit backend".
  4. Under "Build and run settings", find "Environment variables" and click "Add variable".
  5. Set the name to `GCP_PROJECT` and the value to your Google Cloud Project ID.
  6. Save and redeploy your backend.
For Local Development

Step 1: Authenticate Your Local Environment

  1. Ensure you have the Google Cloud CLI (gcloud) installed.
  2. Run the following command in your terminal and log in:
    gcloud auth application-default login
  3. Make sure your Google Cloud Project ID is set in a `.env.local` file in your project root:
    GCP_PROJECT=your-project-id-here

Step 2: Create BigQuery Dataset and Tables

If authentication is correct, the error might be that the required BigQuery tables do not exist. Go to the BigQuery SQL Workspace and run the queries found in the `docs/schema.sql` and `docs/data.sql` files to create and populate your tables.

For Deployed Solutions (IAM Roles)

If setting the environment variable doesn't work, double-check that your service account has the correct permissions. Your deployed app runs as a **service account**, which needs to be granted permission to access BigQuery.

To fix this, go to the IAM page in your Google Cloud Console and grant the following roles to your service account:

  • BigQuery User: Allows running query jobs.
  • BigQuery Data Editor: Allows reading and writing data to tables.
  • Cloud Run Invoker: Allows the Next.js app to call your Cloud Run microservices.

You can find your service account email on the IAM & Admin page. It usually looks like `firebase-app-hosting-compute@...` or `...-compute@developer.gserviceaccount.com`.