Open Closed

Angular - redirect based on user role after login #7131


0
TSG created

Hi, I would like to redirect users to specific routes after login based on their roles.

I'm thinking about decoding the access token to get the user role and then redirect based on the role. /src/account/login/login.service.ts - ln194 Is there a way of getting the role from the access token?

Would you suggest another approach to achieve this?

Thanks, Rui


3 Answer(s)
  • 0
    ismcagdas created

    Hi @TSG

    Current token doesn't contain this information. You can add users roles to UserLoginInfoDto.cs and return it on GetCurrentLoginInformations method of SessionAppService. So, Angular client can use this inforamtion and route user accordingly.

  • 0
    TSG created

    Hi @ismcagdas,

    Thanks for the suggestion. I have mention getting the role from the access token because I can see the roles on the token claims

    { "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "2", "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name": "admin", "AspNet.Identity.SecurityStamp": "ad2a1564-1e74-03e4-95ed-39ee2fc7279b", "http://schemas.microsoft.com/ws/2008/06/identity/claims/role": "Admin", "http://www.aspnetboilerplate.com/identity/claims/tenantId": "1", "sub": "2", "jti": "6894167b-4e59-4f5f-b289-dea08f80673b", "iat": 1559923693, "token_validity_key": "a9effec1-16d0-4cb7-b172-3524e2ed5ae9", "user_identifier": "2@1", "nbf": 1559923693, "exp": 1560010093, "iss": "TSG", "aud": "TSG" }

  • 0
    ismcagdas created

    Hi @TSG,

    Sorry, it seems like I remembered it wrong. You need to find a client side library to decode JWT token. After that, you can use the role.