422 on Identity Signup

Update 2/10/2022 6:51PM CST


  • The error message: {"code":422,"msg":"Failed to handle signup webhook"} is being returned for all functions, not just the signup function. If I only use the my validate function, the same error is returned.
  • I had to select “Clear cache and deploy site” for it to not reference my functions
  • I created one function and I’m setting the webhook url in the identity setup.
  • Working Solution: To get it to finally work, I had to use the “callback” rather than returning the object. I’m using netlify-lambda build to build the functions as I “THINK” this might be the culprit since not using it without the “callback” seems to work.

Below is my new working function:

export const handler: Handler = (event: HandlerEvent, context: HandlerContext, callback) => {
  const data = JSON.parse(event.body);
  const { user, event: authEvent } = data;

  console.log(`authEvent: ${authEvent} called for ${user?.email}`);

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

  if (authEvent === 'signup') {
    // Look for phone number and team and send a notice to register
    console.log(`${authEvent}: Event signup.  Do stuff`);
  }

  if (authEvent === 'login') {
    console.log(`${authEvent}: Event login. Do stuff`);
  }

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

I am having an issue with a new site during the webhook invocation for identity-signup. It's a very simple function `identity-signup`
export const handler: Handler = (event: HandlerEvent, context: HandlerContext) => {
    const response {
        statusCode: 200,
        body: JSON.stringify({ app_metadata: { roles: ['user'] } }),
    };

    console.log('returned response', response);

    return response;
};

During signup; I observe the function being called (via logs) and the expected response is being returned. However, the response returns a 422 in the website:

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

Interestingly, I overrode the webhook configuration here:

Netlify App[SITE NAME]/settings/identity#webhook

I set the “signup” event to the function’s production url and it works correctly. However, I don’t understand why the feature only allows one url so it’s not going to work for me going forward.

I’ve also reviewed the following topics, but sadly they do not resolve my issue:

Hey @amoline,

I’d advise not using netlify-lambda. In any case, what happens if you return the complete user object with the modified roles instead of just returning the roles?