Environment variables in production

Hey guys!

I have built a small site that uses the Stripe API. I managed to get it working in development environment but as soon as I try to push it to production I get the following error in my console: “IntegrationError: Invalid API Key provided”. So here is what I have done:

I am using environment variables as per Gatsby’s documentation: Environment Variables | Gatsby
As mentioned it works fine in development environment.
In production I have added the live keys to Deploys > Build & Deploy > Environment

Is this the correct way to do it?

Hiya @sgriesel and welcome to our community!

If you use a variable called $GATSBY_* (where * is any valid string) you should be able to use it directly in your gatsby, browser-side code. You may want to instead do a less gatsby-specific thing and use your environment variables by any name, but you do have to interpolate the values yourself in that case! See this article for more details on the best practices there: