FaunaDB 401 unathorized in production with Netlify

Hello!

I am using Netlify (just React) and FaunaDB to create a contact form.
I set up FaunaDB as follow:

const client = new faunadb.Client({
  secret: process.env.REACT_APP_FAUNA_DB || '',
  scheme: 'https',
  domain: 'db.fauna.com' (I tried db.us.fauna.com and db.eu.fauna.com, but only db.fauna.com does NOT fail in dev)
})

and this is the function fired onSubmit the form:

  const createContactMessage = (email: string, subject: string, message: string, isCheckboxSelected: boolean) => {
    client
      .query(
        q.Create(q.Collection('ContactForm'), {
          data: {
            email: email,
            subject: subject, 
            message: message,
            isCheckboxSelected: isCheckboxSelected  
          }
        })
      )
      .then(() => messageSentSuccessfully())
      .catch(() => setIsMessageFailed(true));
  }

the message gets saved when I submit it via localhost:8888.

BUT, once I pushed the changes in Production, the onSubmit fails with a 401 error:

{“errors”:[{“code”:“unauthorized”,“description”:“Unauthorized”}]}

I solved it by adding REACT_APP_FAUNA_DB to the ENV of Netlify:

'Team settings > Sites > Global site settings > Shared environment variables'.

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