MERN: ‘Invalid API Key’ Heroku Deployment?

How do I get Firebase Auth to work on Heroku Deployment?

Auth works in MERN app’s local development without any issues. All private information is stored in an .env file and then called in my react app with process.env.VARIABLE_NAME.

However, when I deploy to Heroku production and add the env files as shown here, I get the error: “Your API key is invalid, please check you have copied it correctly”

This is my deployed Heroku app:


Also, running the command heroku config displays the inputted env variables in the terminal.

Any idea why Auth works locally but not in deployment? Thank you!


Answer because too long for a comment.

Sounds super hard to debug – also your app just shows a login and not the API key error =) To me it sounds like either just like it says, an incorrect API key or a formatting issue.

I would make a test config variable using the same characters as your API key like REACT_APP_FIREBASE_POTATO=p07470-test-example-foooobar and then in your frontend app just console.log("TEST" + process.env.REACT_APP_FIREBASE_POTATO);. Then publish that and check it in production.

This tests are the environment variables working at all and are there some character encoding issues (do you see the exact characters in the console as you should)