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

Hi Jen,
I’m having this same issue with a small test build I’m doing (using Fauna though). I’m trying to use Identity-Fauna-Stripe for assigning roles now but it won’t work (email confirmations won’t trigger and then I eventually get failed to handle signup webhook” errors (when I delete my only member). When I don’t use Fauna/Stripe my sign-in works and redirects work (with manual assignment of role).

I think the issue is the webhook. I’m new to this so I don’t know where to put the URLs that you suggest. I tried in the webhook section of Settings and Usage but the # doesn’t work there so I’m sure I’m wrong about that. I’m willing to try anything at this point but some additional guidance about where these webhooks would live would be most helpful.

Thank you,.

Hi @desidem,

Could you share the site URL?

My site is a demo (based on this tutorial: https://www.netlify.com/blog/2020/07/13/manage-subscriptions-and-protect-content-with-stripe/.) My site URL is: https://admiring-euler-fb69e1.netlify.app/

I’m not sure if that identity-signup file is not triggering OR if the code inside it isn’t right. I’m able to sign up but the roles still have to be input manually. When I sign up there’s no membership activity recorded on my Fauna or Stripe test sites. The schema.gql seems to work in Fauna but other than that no activity. Thank you!

You can also see my folder structure here and the open fauna.js file.

Right now just working with demo files until I can get it to work.
Thank you! Desiree

The easiest way to check that would be adding a console.log statement.

Since the code seems to be same as the one used in the blog post, I’m assuming it’s correct.

Are you using email based login or using social sign-in like Google in your Identity?

Hi. I’m using the email sign-in (not 3rd party). Console.log() yielded nothing. However, I have 2 theories. I’ve moved the function folder around (and deleted it too). I think when it’s completely removed/unrecognizable it doesn’t fire at all but it also doesn’t interfere with Identity sign-up/log-in. When it’s in the right spot, however, it doesn’t fire and it interferes with Identity sign-up/login because i get the message “Email not confirmed.”
When I have the functions folder at root (screenshot in previous) I get this message in the functions log:

Could you share you repo or is it exactly unchanged from that example?

This is the most recent folder view (should be unchanged from last). I deployed from local using Netlify CLI not Github.

I just put committed to Github:

Hi @desidem,

Kindly do not email our staff directly, that’s not an appropriate way to ask for support.

But coming back to your problem, the problem is because you’re using node-fetch version 3. That doesn’t support the require syntax anymore. You need to use version 2 or use the import syntax.

Hello, has there been a fix to this issue?

I have a site that is live where we use identity-signup in the exact same manner as the OP, with the difference that we are using FaunaDB. It’s been live for a long while and used to work just fine. Only recently I have noticed that anyone trying to sign up never gets an account created in our FaunaDB only in the Netlify identity.