Environment Variables not working in Vercel/Netlify

Hello all,

I recently deployed a test app to learn how to use Fauna’s user authentication API. You can see the app here: https://fauna-authentication.vercel.app/

The app works locally, but when it is deployed I get an ‘Unauthorised’ error message when I try to login?

In Vercel/Netlify I have crated an environment variable with the same name that I use locally in my .env.development file: FAUNA_SERVER_SECRET.

What am I missing here? Do I need to whitelist the domain or something?

Thank you for any help.

Someone had a similar issue with Netlify: Error: `unauthorized` when deployed as a function on netlify. Everything works properly locally

Sometimes, the keys that you have saved to the cloud can get out of sync with what you are using locally. Note that a .env.development file will not be used when you deploy.

Are you using both Vercel and Netlify? Your app link is on a Vercel domain. Can you be more specific about what hosting platform you are using?

See the linked Topic for Netlify resources. Vercel’s documentation on env vars is here: Environment Variables – Vercel Docs

I’m using both platforms. Neither of them work. The article that you referenced was not useful unfortunately because they were using the wrong variable. I am using the correct one.

Hi @lucasjohnson. Well, certainly you can use whatever names for your environment variables that you wish. The links that I shared reference Netlify’s and Vercel’s documentation, which should be able to guide you through viewing and updating the environment variables they have stored for you in the cloud. You will need to make sure that they are the same as the ones you are using locally, or otherwise set to the values that you desire.

For example, I shared with you that you can run a CLI command to list the environment variables they have saved for you. You can also view the variables stored with Netlify on your Netlify project page. Their documentation goes into greater detail.

For Vercel, I shared their documentation page for environment variables as well. It states that to declare an Environment Variable for your deployment, head to the Environment Variables page of your Project Settings.

Please confirm that the environment variables for your Netlify and/or Vercel projects have been correctly assigned. You said that your application works locally, so it sounds most likely that the variables have not been set for your production environment.