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!