How do I make an update to my database after first user signup?

I am building a React app, with a Mongo DB db, and an express-based API. After a user registers, I would like to create a new User record in my database and add some default values, such that I can display an appropriate homepage for a signed in user. I have reviewed the Auth0 docs and am not able to locate a clear solution for this.

If I were handling the signup myself via my own API, this would be trivial, as I would just create the record as part of the signup call. However, now it is not at all clear how I can hook into an Auth0 registration event.

One option seems to be to use Hooks, but it’s not clear how I would interface with my API from an Auth0 hook.

Any tips or suggestions would be appreciated!

Hello @andersco,

Welcome to the Community! I suspect you could do this with the post-registration hook or a rule (rules execute after the user logs in). In either case hooks and rules are just javascript, and you have access to a large library of modules to leverage (Can I require? - Search which node modules you can use in webtask.io). A hook or rule can call an API to create the database record, or you can call the database directly.

Thanks for the suggestion.

My understanding is that hooks are defined by snippets of code that are added via the Auth0 dashboard.

In order to update a User record in my database, the hook would need to supply the proper credentials to the db server. How can I securely pass in my db credentials to a hook? (Normally, I would do that via an environment variable but not clear how that works for a hook.)

Think I found the answer: Hook Secrets

2 Likes

You got it … both hooks and rules can use configuration variables / secrets stored within Auth0. For rules:

1 Like

Thanks for sharing that link Mark!