# How to redirect admins to a specific page?

**URL:** <https://community.auth0.com/t/how-to-redirect-admins-to-a-specific-page/59372>\
**Category:** Get Help\
**Tags:** auth0\
**Created:** [March 13, 2021, 4:39pm UTC](https://community.auth0.com/t/how-to-redirect-admins-to-a-specific-page/59372 "2021-03-13T16:39:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gutisAlex](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gutisalex/32/14464_2.png) [@gutisAlex](https://community.auth0.com/u/gutisAlex)\
**Post date:** [March 13, 2021, 4:39pm UTC](https://community.auth0.com/t/how-to-redirect-admins-to-a-specific-page/59372/1 "2021-03-13T16:39:19Z")

</div>

Is there a rule I can use to redirect all users with the role admin to [example.com/admin](http://example.com/admin) ?

Ofc this url should only be accesible by admins!

---

<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:** [March 16, 2021, 11:09am UTC](https://community.auth0.com/t/how-to-redirect-admins-to-a-specific-page/59372/3 "2021-03-16T11:09:17Z")

</div>

Hi @gutisAlex,

Thanks for joining the Community!

I will see if I can get a rule working for that. You may have already found this, but just in case, here is some documentation after log-in redirects: [Redirect Users](https://auth0.com/docs/users/redirect-users-after-login)

---

<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:** [March 16, 2021, 1:27pm UTC](https://community.auth0.com/t/how-to-redirect-admins-to-a-specific-page/59372/4 "2021-03-16T13:27:12Z")

</div>

As suggested in [Once user authenticated, how do I redirect the url based on role? - #2 by dan.woda](https://community.auth0.com/t/once-user-authenticated-how-do-i-redirect-the-url-based-on-role/29632/2), one solution would be to pass the role as a custom claim in the ID Token and redirect the user based on their role.

> **[Sample Use Cases: Rules with Authorization](https://auth0.com/docs/manage-users/access-control/sample-use-cases-rules-with-authorization?_ga=2.169357417.97902719.1615807267-1595415333.1607347674)**
>
> Learn how to use rules with roles-based access control (RBAC). For use with our Authorization Core feature set.

---

<div class="post-metadata">

**Author:** ![gutisAlex](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gutisalex/32/14464_2.png) [@gutisAlex](https://community.auth0.com/u/gutisAlex)\
**Post date:** [March 19, 2021, 7:55am UTC](https://community.auth0.com/t/how-to-redirect-admins-to-a-specific-page/59372/5 "2021-03-19T07:55:26Z")

</div>

The guy himself said it can be done in a numerous ways… I am already passing the roles via token and I probably would have some ideas to implement a way into my app to redirect an admin to the admin page but how about [Redirect Users from Within Rules](https://auth0.com/docs/rules/redirect-users) ? I managed to redirect an Admin to the page by simply using this rule:

```
function (user, context, callback) {
  if(context.authorization.roles.includes('Admin')) {
  	context.redirect = {
  		url: "http://localhost:8080/admin"
  	};
  }
  return callback(null, user, context);
}

```

Only problem right now is I am running into and endless loop… I didnt quite understand the part where I have to redirect to the continue endpoint… So when going on localhost:8080/admin I have to take the state from the url and redirect to localhost:8080/continue?state=THE\_ORIGINAL\_STATE and the auth0 side now would know all is fine and redirect me back to my admin site eventhough I dont even have that endpoint?!

So basically before anything gets rendered on my admin page I check if there is a state in the url, if so I redirect to localhost:8080/continue?state=abc123 and if not I stay?!

I probably have to extend the rule by the validate resumed login rule also?

---

<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:** [March 19, 2021, 6:29pm UTC](https://community.auth0.com/t/how-to-redirect-admins-to-a-specific-page/59372/6 "2021-03-19T18:29:48Z")

</div>

The [Redirect Users from Within Rules](https://auth0.com/docs/rules/redirect-users?_ga=2.72954843.97902719.1615807267-1595415333.1607347674) functionality takes place _before_ authentication is finished. It is primarily used as a way to additional steps to the user registration process such as a privacy agreement step. The user is not logged until you redirect them to the `https:YOUR_AUTH0_DOMAIN.com/continue?state=THE_ORIGINAL_STATE`.

> [@gutisAlex](#):
>
> So when going on localhost:8080/admin I have to take the state from the url and redirect to localhost:8080/continue?state=THE\_ORIGINAL\_STATE

It would be your Auth0 tenant’s `/continue` endpoint instead of your app’s.

Only one redirect can take place during the login process via a rule.

The redirect rule doesn’t seem like the functionality you are looking for since you’d like to redirect the user _after_ authentication. Whereas the redirect rule is for adding additional steps to the login process.

---

<div class="post-metadata">

**Author:** ![gutisAlex](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gutisalex/32/14464_2.png) [@gutisAlex](https://community.auth0.com/u/gutisAlex)\
**Post date:** [March 20, 2021, 8:56am UTC](https://community.auth0.com/t/how-to-redirect-admins-to-a-specific-page/59372/7 "2021-03-20T08:56:17Z")

</div>

Ok I worked out a solution on my end using react hooks…

So the [Redirect Users From Within Rules](https://auth0.com/docs/rules/redirect-users?_ga=2.72954843.97902719.1615807267-1595415333.1607347674) functionality would come in handy if I have smth like an onboarding, where a user has to provide additional infos, like an address, nationality, ect.?! So when visiting my site I am getting redirected to onboarding, put in extra information, which I send to my own backend, and if that worked I redirect to [myapp.eu.auth0.com/continue?state=123](http://myapp.eu.auth0.com/continue?state=123) and the authentication would continue sending me to the main page?! Is that the flow of this feature? I probably need a custom prop on auth side to check if hasOnboarded or not?!

---

<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:** [March 22, 2021, 4:34pm UTC](https://community.auth0.com/t/how-to-redirect-admins-to-a-specific-page/59372/8 "2021-03-22T16:34:37Z")

</div>

Yes, that is correct! The redirect users from within rules functionality would be helpful for an onboarding step. Yes, you are right about including the `hasOnboarded` property. You could store this in the user’s app\_metadata and check for the key before changing the redirect URL.

---

<div class="post-metadata">

**Author:** ![gutisAlex](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gutisalex/32/14464_2.png) [@gutisAlex](https://community.auth0.com/u/gutisAlex)\
**Post date:** [March 30, 2021, 6:06pm UTC](https://community.auth0.com/t/how-to-redirect-admins-to-a-specific-page/59372/9 "2021-03-30T18:06:55Z")

</div>

ok but how am I setting up the onBoarding prop to every new user registration? I was reading the [https://auth0.com/docs/users/set-metadata-properties-on-creation](https://auth0.com/docs/users/set-metadata-properties-on-creation) article but I dont really understand it… I am using the universal login, and over this people register as well, I dont really have anything to do with the whole registration process… So where am I setting this up?

Edit: I managed to set the prop via hooks…

---

<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:** [April 14, 2021, 6:07pm UTC](https://community.auth0.com/t/how-to-redirect-admins-to-a-specific-page/59372/10 "2021-04-14T18:07:29Z")

</div>

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