# How can I redirect the user based on his role after logging in?

**URL:** <https://community.auth0.com/t/how-can-i-redirect-the-user-based-on-his-role-after-logging-in/125371>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [January 22, 2024, 5:01pm UTC](https://community.auth0.com/t/how-can-i-redirect-the-user-based-on-his-role-after-logging-in/125371 "2024-01-22T17:01:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![borjan.kalinoski](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/borjan.kalinoski/32/54133_2.png) [@borjan.kalinoski](https://community.auth0.com/u/borjan.kalinoski)\
**Post date:** [January 22, 2024, 5:01pm UTC](https://community.auth0.com/t/how-can-i-redirect-the-user-based-on-his-role-after-logging-in/125371/1 "2024-01-22T17:01:25Z")

</div>

After a user logs in, I must redirect him to a specific route based on his user role.

Should this be implemented in the Auth0 Actions or our React Application?

I’ve tried setting properties to the idToken and the accessToken in the auth0 post login actions, but I’ve had no luck retrieving them on the front end so far.

![image](https://global.discourse-cdn.com/auth0/original/3X/d/2/d218917e9de338189adfc45af15e6e834e641347.png)

Is this the way to go, or should I do this in our react application?

If this is the way to go, why am i not able to attach the user-role property to the tokens?

I’ve also tried to use the `api.redirect` function, but no luck there as well. I couldn’t find concrete examples regarding my use case.

Any help is welcome, thanks!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [January 22, 2024, 5:59pm UTC](https://community.auth0.com/t/how-can-i-redirect-the-user-based-on-his-role-after-logging-in/125371/3 "2024-01-22T17:59:23Z")

</div>

Hey there @borjan.kalinoski welcome to the community!

> [@borjan.kalinoski](#):
>
> Is this the way to go, or should I do this in our react application?
> 
> If this is the way to go, why am i not able to attach the user-role property to the tokens?

This is a valid approach and outlined in [this topic](https://community.auth0.com/t/redirect-user-depending-on-role-after-login/83610) - It’s hard to tell from the code snippet shared. Are you defining the `roles` variable elsewhere?

---

<div class="post-metadata">

**Author:** ![borjan.kalinoski](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/borjan.kalinoski/32/54133_2.png) [@borjan.kalinoski](https://community.auth0.com/u/borjan.kalinoski)\
**Post date:** [January 22, 2024, 9:55pm UTC](https://community.auth0.com/t/how-can-i-redirect-the-user-based-on-his-role-after-logging-in/125371/4 "2024-01-22T21:55:28Z")

</div>

hi @ty.frith

For now, the roles variable has a hardcoded value like: `const roles = 'test'; // or ['test']`; Ideally, I would fetch the user role somehow from auth0, but I can get back to that later.

From what I understood, i need to do:

1. Call api.redirect.sendUserTo() in the `onExecutePostLogin`, in my case `sendUserTo('localhost:3000/organizations`
2. Then, in my application when the `/organizations` route is called, I need to navigate the user to [https://my-auth-domain.com](https://my-auth-domain.com)
3. Then i need to do something in the `onContinuePostLogin` script, which im not sure why.

I am not quite clear if these are the correct steps, and if they are, im not exactly sure what i need to do in the onContinuePostLogin script, and what kind of data do i need to pass to that script, and to the /continue route.

I can revisit this tomorrow and get back with more details if needed.

Any help is welcome!  
Thanks!

---

<div class="post-metadata">

**Author:** ![borjan.kalinoski](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/borjan.kalinoski/32/54133_2.png) [@borjan.kalinoski](https://community.auth0.com/u/borjan.kalinoski)\
**Post date:** [January 23, 2024, 9:12am UTC](https://community.auth0.com/t/how-can-i-redirect-the-user-based-on-his-role-after-logging-in/125371/5 "2024-01-23T09:12:32Z")

</div>

I’ve managed to make it work by adding the user\_roles property to the idToken.

Here are screenshots for anyone who is facing the same issue:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/7/8/7865f87651e7be307cd7cb112655399394b29e67.png)

 ![image](https://global.discourse-cdn.com/auth0/original/3X/4/9/49ab5ce3c5376e8f88f64e58e052fb303be5f1c3.png)

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [January 24, 2024, 1:27am UTC](https://community.auth0.com/t/how-can-i-redirect-the-user-based-on-his-role-after-logging-in/125371/6 "2024-01-24T01:27:02Z")

</div>

Great! Thanks for sharing with the community 🤠

---

<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:** [February 7, 2024, 1:27am UTC](https://community.auth0.com/t/how-can-i-redirect-the-user-based-on-his-role-after-logging-in/125371/7 "2024-02-07T01:27:54Z")

</div>

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