0
votes

Currently I am using ABP version 2.9 (DonetCore, Angular, Mongo) project template.

I need to have a logic to redirect user to different path based on user ROLE.

What I see from the source [here], there is CurrentUser object but it doesn't have roles property.

export interface CurrentUser {
isAuthenticated: boolean;
id: string;
tenantId: string;
userName: string;
email: string;
}

Maybe there is a reason that 'Roles' has not been included to current user?

Is there any way to get the user-role using any service or state?

Also how to add Role as an extra filed to jwt token and get access to that from client side?

1

1 Answers

2
votes

First of all, I don't suggest to write code based on roles. Because roles are dynamic, you can add roles on runtime and can not know the role name in development time. There is an exception: Static roles are known at development time. However, I suggest to go with the permission system wherever possible.

Roles are not accessable in the client side in current design. However, I don't see any good reason to not add them to the currentuser. We can add it, if you create an issue on the GitHub repository.

JWT token is stored in the local storage (as I know - I am not developing the Angular side). If you access it (the access_token), you may extract roles inside it. When I paste it to https://jwt.io/ I can see the role name, so it should be possible.