Sending a user id to our database after signing up

Apologies as I’m sure this has been asked in many different forms before but I’ve not managed to derive a clear answer.

Our use case is we’re using Auth0 to handle our users, but on our backend our users will have quite a lot of data associated with them that we’ll need to relate to a uuid we create in their Auth0 profile.

The post-user-registration action seems ideal for this, however it mentions that its non-blocking:

Actions in this flow are non-blocking (asynchronous), which means the Auth0 pipeline will continue to run without waiting for the Action to finish its execution. Thus, the Action’s outcome does not affect the Auth0 transaction.

Whilst unlikely this does create a scenario where by the user could be created in Auth0 and if there was an error in our backend the user id wouldn’t be sent back to us and we’d have an orphan user floating around.

An alternative approach is using the post-login flow. But we are not sure if this runs after signup as well or only on subsequent logins?

I suspect a fair few people will have solved this problem before so just reaching out to see what the common wisdom is in the hope it may help us avoid going down the wrong path.

Thanks!

fwiw I found an example of what I was looking for in another thread:

exports.onExecutePostLogin = async (event, api) => {
  if (event.stats.logins_count !== 1) {
    // do nothing for subsequent logins, only care about the first one.
    return;
  }

  try {
    // post to our backend here with the user id from the meta data.
  } catch (e) {
    // very rare but incase our backend is unavailable
    console.log(e);
    api.access.deny('Could not log you in at this time');
  }
};

Which redirects to your callback url with the error query params:

https://manage.auth0.com/tester/callback?connection=google-oauth2&error=access_denied&error_description=Could%20not%20clog%20you%20in

I haven’t implemented this yet but this is the direction I’m going to go in

Hey there @ryanhyslop welcome to the community!

Thanks a bunch for the follow up here - Let us know how it goes!

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.