Support Forums

Identity-signup function is not being triggered


I’ve created a identity-signup.js under functions which connects to Hasura to create a new user in the db when a new user signs up.

    const { hasuraRequest } = require("./util/hasura");

    exports.handler = async function (event) {
       const { user } = JSON.parse(event.body);
      const currentDate = new Date(Date.now());

      const data = await hasuraRequest({
        query: `
         mutation insertUser($user_id: String, $username: String, $email: String, $netlify_id: String, $password: String, $created_on: timestamptz) {
          insert_users(objects: {user_id: $user_id, username: $username, email: $email, netlify_id: $netlify_id, password: $password, created_on: $created_on}) {
        variables: {
          user_id: user.id,
          username: user.username,
          email: user.email,
          netlify_id: user.netlify_id,
          password: user.password,
          created_on: currentDate.toLocaleString("en-GB", { timeZone: "UTC" }),
      }).catch((err) => console.error(err));

      console.log(">>>>", user);

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

however this doesn’t get trigger when a new user signs in and confirms his email address.
I’ve also double checked to make sure I have my HASURA_ADMIN env in Netlify.

Any ideas what am I missing?

Hey there, @oanaOM

Thanks for reaching out! Can you share your site name and your function name with us so that we can look into this further? Thank you :slight_smile:

Hi Hillary,

Thanks for getting back to me!
Sure, this my site: https://hook-hasura-and-db--youthful-tesla-6a4b5a.netlify.app/ and the function name is identity-signup. The endpoint is: https://hook-hasura-and-db--youthful-tesla-6a4b5a.netlify.app/.netlify/functions/identity-signup

Hey @oanaOM,
Thanks for that! This looks like a bug on our end. I’ve escalated to our engineering team but unfortunately can’t be sure when this will be fixed. The identity-login event-triggered function seems to be working as expected- would that work for you instead of identity-signup?

1 Like

Thank @jen for getting back to me on this! Unfortunately, identity-login will not work for me as I want to create a new user in my db when someone signs up. I’ll look for other workarounds while this gets fixed.

Please keep me update on this.

We may have fixed this! Could you please try signing up as a new user to your Identity instance and let us know if your function is working better now? Please note that you’ll need to go through the full signup flow, not just make a request to your identity-signup function endpoint via curl, axios, etc.!

Hi Jen,

Thanks for you follow-up! I’ve just give it a try, created a new user by following the sign-up flow and still don’t see any logs in the identity-signup function on netlify. Please advice.

Hey @oanaOM,
What a bummer! Thanks for trying again. At this point, the only thing I can think of is that perhaps Identity event-triggered functions don’t work on branch deploys. Would it be possible to test this on your main branch or test the function on the main branch of another site?

Hey @jen ,

I’ve just merged my branch into master to make a test and it still doesn’t trigger my function. Is there anything else I could try?

Hey there! Thanks for your patience. I’ll look to work with the dev team regarding this and we’ll report back as soon as we hear more!

Yes! One more idea to try, wish I would’ve thought of this earlier: you can create custom webhooks that are triggered on Identity events. Here’s where you would do this in the UI: https://app.netlify.com/sites/SITE_NAME/settings/identity#webhook

And then you would put in the URL of the Netlify function path there, like https://SITE_NAME.netlify.app/.netlify/functions/identity-login-manual-webhook. Please be sure to rename the function so it’s not one of the reserved names for automatically triggered Identity functions- you can just add -manual-webhook to the end.

1 Like