Howto add custom claims during sign-up?

We’re developing an application where users can log into a cloud service to connect to their home device. To do this, users need to provide proof of ownership for their devices.

When signing up with the cloud service we wan’t to register ownership claims with the user’s metadata. We already understand that we can…

  • register the ownership metadata using the management api
  • extract metadata into custom claims in the user’s access token using a post-login action

What’s unclear is how this can be done right after initial signup. It would be nice- if possible- if we could register the user metadata and force-retrieve a new access token. Alternatively, it would be nice if we could register additional user metadata during signup, i.e. when the user logs in for the first time.

Hope the question makes sense, looking forward to an interesting answer!

Cheers,
Andi

After researching a bit more it seems that pre-user-registrationwith a machine-to-machine trigger might be a technical approach to enrich the required data before the token is issued, however Pre-user Registration Trigger says:

You cannot currently use pre-user-registration Actions to add metadata to passwordless users.

I assume passwordless refers to social login (which we’d like to use).

Hi @cpuidle,

Welcome to the Auth0 Community!

The Pre-user Registration Trigger can only be triggered by a Database Connection or a Passwordless Connection. While the action cannot add metadata to users from the Passwordless Connection, it will still be able to trigger the action; a social connection will not even trigger this action.

A Post-user Login Action can be triggered from any Connection.

https://auth0.com/docs/customize/actions/explore-triggers/signup-and-login-triggers/login-trigger

And can be used to manage user metadata:

https://auth0.com/docs/manage-users/user-accounts/metadata/manage-user-metadata

You can check if this is the user’s first time logging in by checking event.stats.logins_count, and then you can execute your code.

https://auth0.com/docs/customize/actions/explore-triggers/signup-and-login-triggers/login-trigger/post-login-event-object

If you have any further questions, don’t hesitate to reach out.

Have a good one,
Vlad