Post-user-registration trigger for actions not called

Hi! I’ve been trying to set up an action to call my api after user registration, the trigger is post-user-registration but it’s just not being called, I set up another action before with the login trigger and it works perfectly in that case, for the user registration I followed these steps

  1. Created custom action
  2. Added packages
  3. Deployed action
  4. Added action to flow
  5. Created a user
  6. Checked logs everywhere

It’s a small piece of code so it was easy to check everything was right, but I’m not getting any logs so I don’t know what’s going on, it’s just not being called so I might try with a hook later if it doesn’t work

It’s calling login action only, see logs

Ps: I should mention I tested it like 30 times at least and it just kept triggering the login action instead. I tried debuggind with the test tool and it gives me a result so I know my api is working

Thank you in advance for checking this!! lmk if you need more information

Hi @nicolascalev !
What type of connection are you using for this? Just to clarify, Post User Registration is for Database and Passwordless connections, not for external identity providers (like social or enterprise connections).
What is your tenant and region?

2 Likes

Hi @nicolas_sabena , thank you for checking this issue

I tested with Database connection a couple times, but now it makes sense that signing up with social connection wasn’t triggering the action. I’m curious about why the database one wasn’t triggering it either tho. Is there an alternative that could be triggered post user signup (either db or social connection), with rules, hooks or actions? if not it’s okay if there’s a workaround to do this

My tenant is dev-nicolascalev and region US-3

Also to give you more background, I’m trying to save the auth 0 user id and some extra info in my database after user sign up

The database user signup should trigger the post user registration every time a new user signs up. Can you still reproduce this issue?

As for external providers “sign up”, a nice and reliable trick is to check for a metadata flag and, if not present, do whatever you want to do on the first login and then write the flag, so that the action is only executed once.

Something like this:

async function (user, context, callback) {
  user.app_metadata = user.app_metadata || {};
  if (!user.app_metadata.signupProcessed) {
    await [...] // do something for a user first login
    user.app_metadata.signupProcessed = true;
    try {
      await auth0.users.updateAppMetadata(user.user_id, user.app_metadata);
      callback(null, user, context);
    } catch (err) {
      callback(err);
    });
  } else {
    callback(null, user, context);
  }
}

Now, a rule like this will also execute the logic for all previously existing users, so if you don’t want that you might want to add additional restrictions, like “if no flag present and user was created after x date”.

3 Likes

Yes I was still able to reproduce this issue :thinking: I did it a couple times, in the screen shot you can confirm that only the login action was triggered, but it’s okay because I liked that workaround!!!

In the other hand, that workaround worked perfectly! I’ll stick to that giveen that it works with social login too, thanks a lot🙌🏽

I’m sharing the code I used in a post-login action, since it uses the api object to update user app metadata, might help someone

const axios = require('axios')
exports.onExecutePostLogin = async (event, api) => {
  // if user has app_metadata and signupProcessed = true, then we don't need to create the user
  if (event.user.app_metadata && event.user.app_metadata.signupProcessed) {
    console.log('User sign up has been processed already')
    return
  }

  try {
    // query app api to store user info
    const { data } = await axios.post('https://yourapi.test/api/user', {
      auth0UserId: event.user.user_id,
      email: event.user.email,
      name: event.user.name,
      picture: event.user.picture
    })
    console.log('User created', data)
    // if everything went well then update signupProcessed to true
    api.user.setAppMetadata('signupProcessed', true)
  } catch (err) {
    console.error(err)
  }
};
3 Likes

Thanks you so much, Nicolas. This was really helpful for me. I really appreciate it when people who figure out how to do something also share their solution.

1 Like

Teamwork makes the dreamwork!

@konrad.sopala This is actually a bug that @nicolas_sabena described, I experience exactly the same thing.

Only Post Login action is being triggered, but not Pre User Registration or Post User Registration.

Any update?

It’s very easy to reproduce it - use passwordless universal login flow, add mentioned actions and try to sign up.

1 Like

Hey @stany thanks for following up on this, and welcome to the community!

@konrad.sopala FWIW I am currently seeing that my pre user registration action is firing, however my post user registration action is not.

@tyf can you reach out to our engineering teams to review that? Thanks!

1 Like

Hey @stany! Just a quick heads up that I have raised this issue with engineering internally and am happy to provide an update as soon as I have more information myself.

1 Like

Hey @tyf

I’ve already checked with your support team on this, the actual Post User Registration trigger is firing, the bug here is that logs are not showing up as part of Action Details, but I was able to see the logs using Real-time Webtask Logs Extension

Ahh ok thanks for the heads up! I was just relying on our logging myself so this is good to know :+1:

1 Like

Following up here - This bug (no action logging in tenant) has been accepted and moved into our Engineering Org’s backlog. Thanks for your help @stany :smile:

1 Like

This topic was automatically closed after 6 days. New replies are no longer allowed.