I’ve currently setup a post-user registration hook that stores the newly created auth0 user in my database, returning an id from the databse to store in the auth0 app_metadata:
Reading through the Pre-User Registration docs however suggests that this might be a better place to add to the app_metadata:
At the Pre-User Registration extensibility point, Hooks let you execute custom actions when a new user is created. For example, you can add custom app_metadata or user_metadata to the newly-created user, or prevent the creation of the user in the database.
Is my current setup using the post-user registration hook ok or should I be doing this in the pre-user registration hook instead?
Thanks for the quick response. I think I’m going to have to use the post-reg hook as I need the user_id from the auth0 user and that isn’t available using pre registration.
To avoid having to store a database id in the users meta data, would it be possible to use the auth0 user_id as an id in the database to reference the user or is that not considered appropriate?
You can also do it in a rule that checks to see if this is the first time the user has logged in, rather than post-reg.
Both methods you mention (storing your user ID in the Auth0 user’s metadata and storing the Auth0 user ID in your DB) are appropriate, with various trade-offs.
As this topic is related to Rules - Hooks - Actions and Rules & Hooks are being deprecated soon I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!