422: Failed to handle signup webhook

Hi, I have seen support topics related to this issue, but I am unable to find a solution. I had set an identity notifcation to signup in the netlify UI. I pasted my serverless function url to get triggered when new users signs up and verifies their account.

This is my function.

exports.handler = async (event, context) => {
  try {
    console.log(event.body);
    return {
      statusCode: 200,
    };
  } catch (err) {
    return { statusCode: 500, body: err.toString() };
  }
};

I do not think I am doing anything crazy, but when I confirm a user after sign-up I get this error.

{"code":422,"msg":"Failed to handle signup webhook"}

It seems verification and signup only work when I do not use netlify webhook events. I created a new site to see if the issue would persist, and It did with the new site. I reviewed goTrue.js code base, this response is being retured from the Webhook trigger function

research links
I have read the netlify trigger events docs

I have reviewed these support message related to the same issue:
422: failed to handle webhook
https://answers.netlify.com/t/identity-signup-function-not-being-triggered-when-verification-link-used-422/47606/13

I also researched example of people using webhooks for other tasks

I am not sure what I am doing wrong, but this should work. If anyone has any insight It would be much appreciated.

You’re not returning any body with the function, which is why I believe it’s not working.

@hrishikesh much appreciated for your response, I did notice that earlier so I updated my code to this

   return {
      statusCode: 200,
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({}),
    };

But still seeing the issue. Could it be an issue with netlify identity webhooks?

@hrishikesh I also took out the header portion as well.

when confirming a user via /.netlify/identity/verify endpoint it just shows {"code":422,"msg":"Failed to handle signup webhook"} I am starting to think it is a netlify webhook issue. Is it possible to confirm on your end? Thank you again for your time.

Empty body is what’s causing an issue. You need to return a complete User object.

Thank you for the reply, this has been a challenge for me to narrow down the issue. I originally tried with values inside the object and I still was getting the issue. I feel like this could some thing deeper I am having a challenge narrowing down the issue.

To start with, you can simply try returning the user object that you might be receiving in event.body.

@hrishikesh I am still seeing the issue {"code":422,"msg":"Failed to handle signup webhook"} when confirming a user after sign up. I am using the docs as reference, but I could be doing something silly causing this issue. Is this what you had in mind?

dir structure

 /functions
  identity-signup.js
exports.handler = async function (event, context) {
  const { identity, user } = context.clientContext;
  console.log(user);

  return {
    statusCode: 200,
    body: JSON.stringify(user),
  };
};

In this example from the netlify site the author returns an empty strinigied object in the response

  return {
    statusCode: 200,
    body: JSON.stringify({}),
  };

I was doing that earlier, but experiencing a different outcome. This is her repo

Hi @aoloo

That is a deploy-failed trigger which not an identity-signup trigger.

As @hrishikesh mentioned

As demonstrated in The role of roles and how to set them in Netlify Identity the sign-up trigger requires a response body that isn’t empty.

This is the identity-signup function I have used/test successfully using code from the above article

@coelmay Thank you for your example site it has been exremely helpful for debugging purposes. I modified my event function to follow the example you had posted, and I was still seeing the 422 error message. I cloned your repo locally and created a new site for testing and I did not see the error. It looks like it is an isolated issue for my one specfic site. The only difference between the sites is the one that I am seeing the issue is using a customized signup flow using gotrue.js api.

I am tempated to nuke my site wit the issue and start over.

@coelmay @hrishikesh I wanted to update you on my status. I started a complete new project to test whether it would resolve my issue. Sadly to say creating a new site did not work for me. If you have any more possible insight, I would greatly appreciate the help.

Hi @aoloo

Is the current code you are using in the identity-signup.js the same as previously posted? If not, can you share that code (or confirm it is the same.)

@coelmay

  const data = JSON.parse(event.body);
  const { user } = data;

  const responseBody = {
    app_metadata: {
      roles: ["basic-user"],
    },
    user_metadata: {
      ...user.user_metadata, // append current user metadata
    },
  };

  console.log(responseBody);

  callback(null, {
    statusCode: 200,
    body: JSON.stringify(responseBody),
  });
};

this is the code I am using

I renamed the function and tried trigging it via netlify ui identity validate nofication. This is what I am seeing when I try to invite users.

I was able to invite a user successfully when I tried (only moments ago.)

I don’t believe this message is anything to do with the identity-signup function is that function is only triggered on successful sign-up and email confirmation (see documentation.)

Do you have a sign-up webhook set under Identity > Notifications > Webhook?

@coelmay No I have validate set on the webhook notifcation. I am at a loss why this is happening. It is hard for me to narrow the root cause.
image

If you remove the identity-signup.js function, does the invite users still give the same error?

Correction when I have signup set I am unable to invite users due to that 422. Inviting users is not working at all for me when I set it with a function.

I renamed the function and set it as a identity nofication in the picture above. When I try to invite users I am getting that error due to the webhook notification being set. When I remove the function and unset the option validate. Then I am able to invite users. Sorry for not being clear.

I am a little confused.

The identity-signup function is one that Netlify automatically triggers on sign-up (as described above.) There is no need to (and nor should you) add this function as a webhook or anything else anywhere—it will just run. The webhook (as set in the UI) will point to other functions/services (a notification endpoint for instance) and triggers when one of the three events happen.

If after unsetting the validate (or other) webhook inviting users works, it is that endpoint is failing.

@coelmay thank you so much for your time. The issue is that identity-signup is not working at all for me. When a user tries to verify their account. We get that 422 as a response. I did not add Identity-signup.js as a webhook. That was a test to see if calling a different function through the UI when certain Identity events happen would the issue occur.

Having identity-signup.js function in the directory will not run at all. A user recieves the email and they click on the link and the response comes back {"code":422,"msg":"Failed to handle signup webhook"}. Even using the same function example you shared earlier I am still seeing the issue.

I following the docs specification and using your example, but it seems something more is causing the issue. I locked at the source code and you can see where the response is coming from.