title: Firebase Functions Service Accounts with Two Projects
body: <p>I have two firebase projects, one for production and one for development. I've created service account keys for both projects and I initialize admin in my functions folder like so:</p>
  <pre><code>const admin = require(&quot;firebase-admin&quot;);
  const serviceAccount = require(&quot;./service-account.json&quot;);
  
  admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    storageBucket: &quot;some-app.appspot.com&quot;,
  });
  const db = admin.firestore();
  
  module.exports = {
    db,
    admin,
  };
  </code></pre>
  <p>But I need firebase to use the appropriate service account for each project. My app is setup to use the production project when deployed in production, but the way I've set up admin.js (above) it always takes the development service-account credentials.</p>
  <p>How can I set the service account credentials as an environment variable? Is there a way to add the key to firebase config in the console? Or should I just hard code in the production service account and live with that?</p>
  <p>I found this in the <a href="https://firebase.google.com/docs/functions/config-env" rel="nofollow noreferrer">docs</a>, but it doesn't appear to solve my problem.</p>
  <pre><code>serviceAccount = require('./serviceAccount.json');
  
  const adminConfig = JSON.parse(process.env.FIREBASE_CONFIG);
  adminConfig.credential = admin.credential.cert(serviceAccount);
  admin.initializeApp(adminConfig);
  </code></pre>
  <p>I appreciate any help you can provide.</p>