Identity-signup Event Triggered Functions

Is there somewhere I could see the structure of objects passed to the function handler for identity-signup event triggered functions? I’m attempting to perform some DB operations on signup so I’m trying to see the name and email of the signup event.

Hi,

We don’t yet have that documented, but you can add the function and console log the event.body to see the shape of the data sent. I just did this and this is the shape of the data I got for a signup event:

    {
        "event": "signup",
        "instance_id": "259498ed-504c-4288-83fa-2c0573sdf3448",
        "user": {
            "id": "2c05df3448-d931-4288-b29c-5959c461f3d2",
            "aud": "",
            "role": "",
            "email": "gerald+5test@netlify.com",
            "app_metadata": {
                "provider": "email"
            },
            "user_metadata": {
                "full_name": "test"
            },
            "created_at": "2019-06-28T15:24:03.237100001Z",
            "updated_at": "2019-06-28T15:24:03.240856829Z"
        }
    }
1 Like

Is there a way I can add something to app_metadata (preferably) or user_metadata when processing the hook? I’d want to store some extra info I could reuse in my logged in user. Cheers

EDIT:

I found this Netlify Identity for paid subscriptions

I’m passing this in my hook

const responseBody = {
        app_metadata: {
            authorization: { roles: ["admin", "editor", "whatever_role_you_want"] }
        },
    };

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

But the netlifyIdentity.currentUser() doesn’t show the authorization data in app_metadata.
Tried with user_metadata as well, same results. :man_shrugging:

1 Like

@abtx, the following post in a similar topic should answer this:

To summarize that answer, using Identity for storing additional fields (in other words, additional user details) is not recommended.

1 Like

hi @luke, thanks for the reply. I’ve already got all user data being pushed to a database on signup like in the post suggested. The method I outlined above should work for setting up custom roles on sign up as well, and that doesn’t seem to work for me. Basically, returning responseBody with app_metadata and the roles doesn’t do anything. I’d like a way to change these programatically and I cannot make it work based on the examples. Can you have a look at the method I referenced and confirm it’s correct? Thanks

Hi @abtx,

You can return an updated app_metadata and user_metadata using the signup webhook. We do this in production now on several private websites. Can you share the function you are using so I can see how you have it setup?

Hi @futuregerald,

ok, this is the code, it triggers the hook successfully and returns 200. I’m testing the hook with Ngrok, but that shouldn’t make any difference.

exports.handler = async (event, context, callback) => {

console.log(chalk.red(‘hook triggered’))

try {

const responseBody = {
  app_metadata: {
      authorization: { roles: ["admin", "editor", "whatever_role_you_want"] }
  },
}

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

}

catch (err) {
return {
statusCode: 400,
body: JSON.stringify({
data: err
}),
}
}
}

Hi, can link me to the site that you have this setup on? Also have you tried returning the roles array in app_metadata rather than in authorization?

@futuregerald, it’s for mybepo.co.uk. I’ve not tried returning the roles yet. Let me have a look and come back to you.

@abtx, that site doesn’t have a netlify function setup for identity signup webhook. it has an ngrok webhook setup right now. Which of your functions that are deployed are you trying to use to return the new app metadata?

I see I’ve removed the code in question from customer-created.js. I’ve created a new webhook called customer-created-metadata.js and it’s now hooked up using Netlify.

It looks like you’ve configured that function to just act as a notification webhook. What you are trying to do won’t work that way. You’ll need to remove the function from the notification setting and rename is as identity-signup.js. As mentioned in our docs, this will make that function an event-triggered function. Let me know if that helps.

hi @Dennis, that’s exactly where I was wrong. I was missing the point with the event webhooks, thanks a lot for pointing this out. It’s all working now. Cheers.

1 Like

On related note, are there plans to support identity-signup and validate with 3rd party providers any time soon?

Could you go into a bit more detail on what that would look like? I’m not sure I understand what you meant. :sweat_smile:

Hi @Dennis, no worries :slight_smile: what i mean is if there are plans to make hooks like on validate, signup, etc. that will fire up if someone signs up with 3rd party service?

If it’s a third-party service, you could just deploy the function as you normally would and use that function’s full url (looks like https://my-netlify-subdomain.netlify.com/.netlify/functions/myfunctionname) as the hook. You’ll probably need to configure triggering that url on the third-party service’s side.

1 Like

@Dennis why didn’t I think of that, makes sense :sweat_smile: I’ll thanks for pointing me in the right direction :bowing_man:

Glad to help! :+1: Let me know how it works out for you.

Mine is called “identity-signup.js”. Modified so it only logs event, context and returns a 200 status code. I’m able to create users but seems like the function never gets triggered, or at least the logs are empty.