Support Request – Firebase Studio Preview & Environment Variables Subject: Firebase Studio Preview does not allow setting custom environmen
Support Request – Firebase Studio Preview & Environment Variables
Subject: Firebase Studio Preview does not allow setting custom environment variables (Admin SDK / Service Account issue)
Hello Firebase Studio Support Team,
I’m using Firebase Studio (Cloud Workstations) with a Next.js (App Router, Server Actions) project that uses Firebase Admin SDK to write to Firestore.
I’m encountering a blocking issue with environment variable management in Firebase Studio Preview.
🔍 Problem Description
My application requires a service account to initialize Firebase Admin SDK.
Normally this is done via an environment variable such as:
FIREBASESERVICEACCOUNT_KEY=<base64-encoded service account JSON>
However, in Firebase Studio Preview:
There is no UI or documented way to define custom environment variables or secrets
Preview automatically injects GOOGLEAPPLICATIONCREDENTIALS
This causes Admin SDK to fall back to Application Default Credentials (ADC)
ADC fails in Preview with errors like:
Getting metadata from plugin failed
Could not refresh access token (HTTP 500)
Even when using dotenv or runtime logic, this cannot be overridden because the env is injected before the Node process starts.
📜 What I Tried
Removing GOOGLEAPPLICATIONCREDENTIALS from .env
Forcing credentials in code (cert(serviceAccount))
Using dotenv
Using Firebase CLI (functions:config:set)
Restarting / rebuilding Preview
Searching for Preview env / secrets configuration
None of these allow injecting a custom env variable into the Preview runtime.
❓ Questions
Is it currently supported to define custom environment variables or secrets for Firebase Studio Preview?
If yes, where is this documented or configured?
If not, is there a recommended workflow for projects using:
Next.js Server Actions
Firebase Admin SDK
Firestore writes
Is Preview intended only as a frontend-only viewer, not a backend runtime?
🎯 Impact
This limitation prevents:
Testing Admin SDK logic
Firestore write operations
Any backend logic that depends on secure credentials
At the moment, the only working solution is local development or Cloud Run/App Hosting, which defeats the purpose of Preview for full-stack apps.
Thank you for your help.
Clarification or documentation on this would be very valuable.
Best regards,
Murat
-
Chris Barnes commented
https://community.firebasestudio.dev/t/environment-variables/644
https://firebase.google.com/docs/studio/customize-workspaceIn Firebase Studio (previously Project IDX), environment variables are primarily managed through the .idx/dev.nix file for the development workspace and within .env files or the Firebase console for deployed services like Cloud Functions and App Hosting.
In the Firebase Studio Workspace (Development)
For variables needed within your cloud-based development environment (the workspace itself), you should use the Nix configuration file:
- Locate the file: Find the .idx/dev.nix file in the root of your project directory.
- Add variables: Within the env attribute set, define your variables. This makes them available to your workspace's terminal and processes.For sensitive information, avoid committing these values directly to your repository. Firebase Studio is actively looking at integrating with Cloud Secret Manager for private values.
---------------
For Firebase Services (Deployment)
When deploying to Firebase services like Cloud Functions or App Hosting, there are different methods:- Cloud Functions: You can load environment variables from a local .env file in your functions/ directory during deployment using firebase deploy --only functions. For managing secrets securely in Cloud Functions, Firebase also supports using its Secret Manager integration.
- App Hosting: Environment configuration is specified in the apphosting.yaml file. You can define variables and specify their availability (build-time, run-time, or both).
For Next.js apps on App Hosting, standard .env files also work. To make a variable accessible in the browser, you can use the NEXT_PUBLIC_ prefix, similar to local development.