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.

The Vercel integration is weird. It creates some FAUNA_ADMIN_KEY with some DB, but that DB has no FAUNA_ADMIN_KEY defined in the security tab in the dashboard. It’s confusing.

The key made through the Vercel integration is saved to your root database and scoped to your new database. That is, if the name of your vercel-integrated database is “vercel-fauna-test”, then the key is created same as if you did the following:

  role: "admin",
  database: Database("vercel-fauna-test") // means this key is scoped to a child database

It’s visible if you use the shell to list keys in your root database.

fauna shell
Connected to https://db.fauna.com
Type Ctrl+D or .exit to exit the shell
> Map(Paginate(Keys()), ref => Get(ref))
  data: [
      ref: Ref(Keys(), "321857201216946769"),
      ts: 1643205796395000,
      role: 'admin',
      database: Database("vercel-fauna-test"),
      data: {
        name: 'VercelConnector:vercel-fauna-test:FAUNA_ADMIN_KEY',
        integration_info: {
          vercel_connector: {
            project_id: 'prj_----------------',
            project_name: 'vercel-fauna-test',
            configuration_id: 'icfg_-----------------'
      hashed_secret: '----------------------'

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.