Try to retrieve origin in hook for multiple environments


I set up multiple environments for my infrastructure related by feature like https://www.[feature name]

And need to know the origin for redirect the user sync on good API.

Do you have any hints for this problem ?

Thank you

Hi @florian1,

Welcome to the Community!

Can you please provide more information about your implementation such as which technologies you are using? At which point in the authentication pipeline do you need the sub-domain? Is it inside a rule, or simply redirecting after using Universal Login?

Thank you!

Thank you for the welcome.

It’s for the Post-User Registration hook.

When a user registers through my interface which has its own url, I want to retrieve this url.

I need to use the source url to redirect the data. → auth0 registration → hook (retrieve


If the created user come from, I want to retrieve this url.

This is my hook

// Post-User Registration

const axios = require("axios");

module.exports = function (user, context, cb) {
  // const url = `${context.origin}/api/rest/webhooks/auth0/post-user-registration`
  const url = "", { user })
    .finally(function () {

I have multiple database, and I need to know origin for redirect the data.

In my configuration, each git branch has its own deployment and I use the subdomain to differentiate them.

I use react on front.

Thanks for providing this information!

Unfortunately, the context object in the post-user registration hook does not contain the app origin URL. One option would be to use the Classic Universal Login Experience and customize the Lock template to use a hidden field in the additionalSignupField setting.

In your React app, you’d pass the feature in the login request:

loginWithRedirect({feature: 'feature_upload-file'})

And you would customize the login template by going to Branding > Universal Login in your Auth0 dashboard. Go to the Login tab and enable the Customize Login Page setting and select the Lock option from the template dropdown. Add the feature in the additionalSignupFields:

    var feature = config.extraParams.feature;
    // Available Lock configuration options:
    var lock = new Auth0Lock(config.clientID, config.auth0Domain, {
      // ... Other lock settings
      additionalSignUpFields: [{
        type: "hidden",
        name: "feature",
        value: feature

And then the feature would be available to the hook via the user’s metadata user.user_metadata.

As a side note, will you have any connection types besides database (username/password) such as login with Google or Facebook, etc.? If so, you may want to consider using a rule instead since the post-user registration hook will only run after a database user is created. Also, if this API request should be made when the same person creates an account for different apps using the same database connection, then a rule would also be better suited since the post-registration script will only run when the user signs up the first time for the connection.

Also, the rule context object does contain the redirect URL and any other params you pass during authentication, so it’d likely be easier to implement this. You would not have to use the Classic Universal Login Experience nor customize the login if you were to use a rule.

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