# Try to retrieve origin in hook for multiple environments

**URL:** <https://community.auth0.com/t/try-to-retrieve-origin-in-hook-for-multiple-environments/60944>\
**Category:** Get Help\
**Tags:** hooks, auth0\
**Created:** [April 12, 2021, 8:51am UTC](https://community.auth0.com/t/try-to-retrieve-origin-in-hook-for-multiple-environments/60944 "2021-04-12T08:51:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![florian1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/florian1/32/28733_2.png) [@florian1](https://community.auth0.com/u/florian1)\
**Post date:** [April 12, 2021, 8:51am UTC](https://community.auth0.com/t/try-to-retrieve-origin-in-hook-for-multiple-environments/60944/1 "2021-04-12T08:51:52Z")

</div>

Hello,

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

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

Do you have any hints for this problem ?

Thank you

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 12, 2021, 1:22pm UTC](https://community.auth0.com/t/try-to-retrieve-origin-in-hook-for-multiple-environments/60944/3 "2021-04-12T13:22:47Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![florian1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/florian1/32/28733_2.png) [@florian1](https://community.auth0.com/u/florian1)\
**Post date:** [April 12, 2021, 3:12pm UTC](https://community.auth0.com/t/try-to-retrieve-origin-in-hook-for-multiple-environments/60944/4 "2021-04-12T15:12:57Z")

</div>

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.

my\_url.domain.com → auth0 registration → hook (retrieve `my_url.domain.com`)

##### Example:

If the created user come from `https://feature_upload-file.domain.com`, I want to retrieve this url.

This is my hook

```js
// 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 = "https://feature_upload-file.domain.com/api/rest/webhooks/auth0/post-user-registration"

  axios.post(url, { user })
    .finally(function () {
      cb();
    });
 
};

```

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.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 12, 2021, 5:24pm UTC](https://community.auth0.com/t/try-to-retrieve-origin-in-hook-for-multiple-environments/60944/5 "2021-04-12T17:24:28Z")

</div>

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:

```auto
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`:

```auto
    var feature = config.extraParams.feature;
    // Available Lock configuration options: https://auth0.com/docs/libraries/lock/v11/configuration
    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](https://auth0.com/docs/rules/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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [June 25, 2021, 1:00pm UTC](https://community.auth0.com/t/try-to-retrieve-origin-in-hook-for-multiple-environments/60944/6 "2021-06-25T13:00:17Z")

</div>

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