# Redirect a user to url via Auth0 Rules

**URL:** <https://community.auth0.com/t/redirect-a-user-to-url-via-auth0-rules/25764>\
**Category:** Get Help\
**Tags:** rules, auth0\
**Created:** [May 27, 2019, 9:36pm UTC](https://community.auth0.com/t/redirect-a-user-to-url-via-auth0-rules/25764 "2019-05-27T21:36:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![maximilian\_cs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/maximilian_cs/32/13061_2.png) [@maximilian\_cs](https://community.auth0.com/u/maximilian_cs)\
**Post date:** [May 27, 2019, 9:36pm UTC](https://community.auth0.com/t/redirect-a-user-to-url-via-auth0-rules/25764/1 "2019-05-27T21:36:37Z")

</div>

I am currently using multiple rules to evaluate different user stages. This is the first rule that gets executed. However the rule redirection to the custom URL is not working. Also new users are getting redirected to the application and not the custom URL. The URL was already added to the list of Allowed Callback URLs.

```
function (user, context, callback) {

  console.log('RULE: Running Set roles of new users');
  console.log('[before] user.app_metadata: ' + user.app_metadata);
  
  user.app_metadata = user.app_metadata || {};

  if (user.app_metadata.signedUp) {
    console.log('This is not the first sign in.');
    return callback(null, user, context);
  }

    user.app_metadata.signedUp = true;
    user.app_metadata.roles = ["Not Approved user"];
    auth0.users.updateAppMetadata(user.user_id, user.app_metadata)
      .then(function () {
        console.log('[after] user.app_metadata: ' + user.app_metadata);
        context.redirect = {          
          url: "https://example.com"
        };
      console.log('Redirect to custom success page');
      return callback(null, user, context);
      })
      .catch(function (err) {
        callback(err);
      });
}

```

However this line gets fired and the output is visible in the console. `console.log('Redirect to custom success page');`

**Why is the redirection not working?**

@konrad.sopala

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [May 28, 2019, 12:55pm UTC](https://community.auth0.com/t/redirect-a-user-to-url-via-auth0-rules/25764/3 "2019-05-28T12:55:59Z")

</div>

Hey there!

Let me check it and get back to you with my thoughts!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [May 28, 2019, 1:20pm UTC](https://community.auth0.com/t/redirect-a-user-to-url-via-auth0-rules/25764/4 "2019-05-28T13:20:04Z")

</div>

So first things first:

- You can redirect a user **once** per authentication flow. If you have one rule that redirects a user, you cannot invoke a second rule to redirect the user at a later time.
- Redirect Rules won’t work with:
  - [Resource Owner endpoint](https://auth0.com/docs/api/authentication/reference#resource-owner)
  - [Password exchange](https://auth0.com/docs/api-auth/grant/password)
  - [Refresh Token exchange](https://auth0.com/docs/tokens/refresh-token#rules).

> **[Redirect Users from Within Rules](https://auth0.com/docs/customize/rules/redirect-users)**
>
> Learn how to customize authentication flows by redirecting users using rules. Example areas that can be customized include MFA, privacy policy acceptance, and gathering user data.

Can you check whether the first bullet point is not a problem here? Thank you!

---

<div class="post-metadata">

**Author:** ![maximilian\_cs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/maximilian_cs/32/13061_2.png) [@maximilian\_cs](https://community.auth0.com/u/maximilian_cs)\
**Post date:** [May 28, 2019, 4:22pm UTC](https://community.auth0.com/t/redirect-a-user-to-url-via-auth0-rules/25764/5 "2019-05-28T16:22:35Z")

</div>

@konrad.sopala If the authentication is successful, the user gets redirected to the application.

If a user creates an account via Auth0 Lock they get automatically signed in. That’s their first sign in and and they should get redirected to a custom webpage on my server that says: “SignUp was successful”  
I have a rules that takes care of this.

For more information please check the rules in my tenant because of the sensitivity of the data.

---

<div class="post-metadata">

**Author:** ![maximilian\_cs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/maximilian_cs/32/13061_2.png) [@maximilian\_cs](https://community.auth0.com/u/maximilian_cs)\
**Post date:** [June 1, 2019, 10:59am UTC](https://community.auth0.com/t/redirect-a-user-to-url-via-auth0-rules/25764/6 "2019-06-01T10:59:19Z")

</div>

@konrad.sopala Any new ideas on this?

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 7, 2020, 11:01am UTC](https://community.auth0.com/t/redirect-a-user-to-url-via-auth0-rules/25764/7 "2020-07-07T11:01:22Z")

</div>

Hey there!

Terribly sorry for the delay in response! We’re doing our best in providing you with best developer support experience out there but sometimes the number of incoming questions is too big.

Can you let me know if you’re still struggling with that? I checked the code snippet and compared it with our docs and when it comes to this rule that you shared the redirect should happen and is triggered the right way. Are you sure that there isn’t another rule that can be conflicting with this one?

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 21, 2020, 4:05pm UTC](https://community.auth0.com/t/redirect-a-user-to-url-via-auth0-rules/25764/8 "2020-07-21T16:05:56Z")

</div>

This topic was automatically closed after 14 days. New replies are no longer allowed.
