Netlify won't write to Fauna DB

I’m following the learnwithjason.dev tutorial on Netlify-Stripe-Fauna integration for subscriptions. I clone the repo from here.

As I’m following the tutorial from the beginning, I overwrite functions/identity-signup.js with the following code:

const fetch = require('node-fetch');

exports.handler = async(event) => {
  const { user } = JSON.parse(event.body);
  console.log(JSON.stringify(user, null, 2));
  
  const netlifyID = user.id;
  
  const stripeID = 1;
  
  const response = await fetch('https://graphql.fauna.com/graphql',{
  	method: 'POST',
  	headers: {
  		Authorization: 'Bearer ${process.env.FAUNA_SERVER_KEY}',
  	},
  	body: JSON.stringify({
  		query:  `
  			mutation ($netlifyID: ID! $stripeID: ID!) {
  				createUser(data: {netlifyID: $netlifyID, stripeID: $stripeID}){
  					netlifyID
  					stripeID
  				}
  			}
      `,
  		variables: {
  			netlifyID,
  			stripeID,
  		},
  	}),
  })
  
  	.then((res) => res.json())
  	.catch((err) => console.error(err));
  	
  console.log({ response })

  return {
    statusCode: 200,
    body: JSON.stringify({ app_metadata: {roles: ['sub:free'] } })
  };
};

Upon a test signup on the website, I get entries in Netlify ID but nothing in Fauna. I’ve already pasted the Fauna server key into Netlify as an environment variable. What am I missing? Been tearing my hair out for the past 2 days.

Thanks!

Hi @witolot - welcome to Fauna!

Can you post a link to the tutorial? I’m finding a few but none seem to use the linked repo.

Hi @rob , thanks for the reply! I may be replying with a lag due to the difference in time zones. Please bear with me.

The written up tutorial is available here. Sorry I didn’t reference it earlier, my posts get blocked if I include too many hyperlinks since I’m a new account.

You’re right about lack of links to the repo. In the tutorial, they actually build the Gatsby site progressively from scratch and don’t actually reference a finalised repo explicitly. The code I posted above for functions/signup-identity.js is from the accompanying Youtube video for the tutorial at the 1h06min timestamp. But even if I use the finalised repos without changes I still have issues writing to Fauna, even though writing to Netlify ID and Stripe work fine.

There are two repos that seem like final versions, each with a different identity-signup.js version:

  1. learnwithjason/stripe-jamstack-subscriptions
const { faunaFetch } = require('./utils/fauna');
  1. jlengstorf/jamstack-subscriptions
const fetch = require('node-fetch');

I haven’t been able to reach the author.