I’m using v4 to set up a simple db to store data in my Gatsby / React web application. The submission works locally, but as soon as I push it into my sandbox branch to test live it stops working.
I have checked the other posts in the forum which consistently point back to an issue with the variable in Netlify or how it’s referenced somewhere else. Going over this possibility I have not been able to correct the issue. I double and triple checked that the variables matched between Fauna dashboard, .env and Netlify env variables - they all matched but still had the error so instead I just revoked the keys and created new ones and updated Netlify env and local env.
Here’s my variables:
const client = new Client({
secret: process.env.SERVER_FAUNA_SECRET,
})
const q = faunadb.query
const rejectDb = process.env.TESTX_FAUNA_COLLECTION
const successDb = process.env.TEST_FAUNA_COLLECTION
Here’s the error:
Error checking email existence: Unauthorized: unauthorized. Check that endpoint, schema, port and secret are correct during client’s instantiation
Here’s the code that threw the error:
try {
// check if email is already in database
const doesEmailExist = await client.query(
q.Exists(q.Match(q.Index('byEmail'), body.email))
)
// function to send form data to fauna - reject
if (doesEmailExist) {
setError('You are already entered to win.')
console.log(
'This email has already been entered and cannot be entered again.'
)
return false
}
await client.query(
q.Create(q.Collection(rejectDb), {
data: {
name: body.name,
email: body.email,
},
})
)
return true
} catch (error) {
console.error(`Error checking email existence: ${error}`)
setError('Error: Unable to verify email.')
return false
}
Anyone have any ideas?