# How to redirect after login based on roles

**URL:** <https://community.auth0.com/t/how-to-redirect-after-login-based-on-roles/80472>\
**Category:** Get Help\
**Created:** [March 24, 2022, 3:16pm UTC](https://community.auth0.com/t/how-to-redirect-after-login-based-on-roles/80472 "2022-03-24T15:16:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nc14](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nc14/32/33226_2.png) [@nc14](https://community.auth0.com/u/nc14)\
**Post date:** [March 24, 2022, 3:16pm UTC](https://community.auth0.com/t/how-to-redirect-after-login-based-on-roles/80472/1 "2022-03-24T15:16:16Z")

</div>

I’m using an action to try redirect away from an admin page and to a standard user profile if you don’t have an ‘admin’ role. So anyone with a ‘user’ role should be directed to a normal profile page.

But when I try this…

```auto
exports.onExecutePostLogin = async (event, api) => {
  if (event.authorization.roles.includes("user")) {
    api.redirect.sendUserTo("http://localhost:3000/user/profile")
    };
  };

```

My page just says “got redirected too many times” and crashes the app. It’s like an endless redirect loop

How do you implement a redirect like this based on roles?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 25, 2022, 5:11pm UTC](https://community.auth0.com/t/how-to-redirect-after-login-based-on-roles/80472/3 "2022-03-25T17:11:34Z")

</div>

Hi @nc14,

The redirect method in actions is a temporary redirect, and isn’t meant to be used to finish authentication.

> **[Redirect with Actions](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/redirect-with-actions)**
>
> Learn how to use post-login Actions to redirect users before an authentication transaction is complete.

The easiest way to handle this is in your application. If you [add the role to the token](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow#add-user-roles-to-id-and-access-tokens), you can check the role after login and redirect based on that.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 21, 2022, 11:58pm UTC](https://community.auth0.com/t/how-to-redirect-after-login-based-on-roles/80472/4 "2022-04-21T23:58:17Z")

</div>


