422 on identity-signup webhook

site - selftaught-dev.com/
happy-hugle-97373a

Trying to use Netlify identity to handle user signup. It works wonderfully!..Unless I try to use the ‘identity-signup.js’ webhook. It worked great back in November (It could send the user info to my database and update their role in Netlify identity), but then it randomly stopped working and started giving user a “Failed to handle signup webhook” error when they’d try to create a new account on my site (see below img).

I have deleted everything in my identity-signup.js function and this is all I’ve got in it now, but it still gives me a 422 and a “failed to handle signup webhook” error.

exports.handler = function (event, context, callback) {
  callback(null, {
    statusCode: 200,
    body: "Hello, World",
  })
}

Does anyone have any ideas what might be causing this or anything that could point me in the right direction? Been stuck on this for a few days.

Here’s the repo if that helps https://github.com/ghughes13/Portfolio-v2

Hi @ghughes13, I’m not sure what’s going on yet but I do see our logs showing a 403 Forbidden response from your identity-signup.js function. Unfortunately, event-triggered functions don’t show log entries. Could you rename the function and then set an Identity notification here: https://app.netlify.com/sites/happy-hugle-97373a/settings/identity#notifications. This will let you see any logs/errors in the function itself and that would help find out why it’s returning a 403.

1 Like

Did not realize I could do that. Thanks Dennis! I’ll play around with that and see what I can figure out! : )

Is it possible that your application is attempting to register the webhook twice? If you perform a GET request on / webhooks .json, you should be.

Have you figured it out? I’m having the same issue here trying to integrate https://github.com/stripe-samples/netlify-stripe-subscriptions into my Gatsby website.

Yea that’s what I was using too @willowell.

I couldn’t figure out why the identity-signup.js function wouldn’t work/was giving me a 422. When the ‘identiy-signup.js’ function/file doesn’t exist, I can successfully register new users, so I just hacked around it with the info @Dennis gave me.

I set up a webhook here https://app.netlify.com/sites/(YOURSITEID)/settings/identity#notifications and copy/pasted my code from identity-signup.js, and everything works as it should again.

Interesting!

I have not made any changes to the functions from the sample except for running ESLint on them to keep the formatting and style consistent with the rest of my project.

It turned out the problem for me was very silly. In Stripe, I set the products to be one-time thinking they would act as lifetime subscriptions. Evidently, that single change was enough to break

  // subscribe the new customer to the free plan
  await stripe.subscriptions.create({
    customer: customer.id,
    items: [{ price: process.env.STRIPE_DEFAULT_PRICE_PLAN }]
  })

So, creating the customer in Stripe just above that ( const customer = await stripe.customers.create({ email: user.email }) ) worked - the customer would show up in Stripe - but creating the subscription failed because Stripe did not consider my one-time product as a subscription, and then the Fauna DB mutation subsequently failed.

After I set the product to be recurring again, identity-signup.js worked just fine. The HTTP requests and responses were fine, the customer showed up in Stripe with the subscription, and the mutation showed up in Fauna DB.

I did change the structure of the functions, but that does not appear to be significant. Here’s the structure anyway just in case:

functions
├── create-manage-link
│   ├── index.js
│   ├── node_modules
│   ├── package.json
│   └── yarn.lock
├── handle-subscription-change
│   ├── index.js
│   ├── node_modules
│   ├── package.json
│   └── yarn.lock
└── identity-signup
    ├── index.js
    ├── node_modules
    ├── package.json
    └── yarn.lock

Perhaps you happened to make the same mistake I made?

Thanks for help

Nox