Manuela CodingPadawan
Manuela CodingPadawan

Reputation: 486

JHipster - *jhiHasAnyAuthority directive - Display one thing when user and another thing when admin

Goal

To display different layouts according to the kind of user.

Try

I used the jhi directive:

<span *jhiHasAnyAuthority="'ROLE_USER'"> User </span>
<span *jhiHasAnyAuthority="'ROLE_ADMIN'"> Admin </span>

Issue

It works when I'm loggin with the user because its role is only ROLE_USER.

However, when I'm loggin with the admin, since it the admin has two roles ROLE_USER and ROLE_ADMIN, the elements that I would like to be displayed only in the user HMI are also presents in the admin HMI.

How can I bypass this issue, please?

Thanks,

Manuela

Upvotes: 2

Views: 1884

Answers (1)

Ga&#235;l Marziou
Ga&#235;l Marziou

Reputation: 16284

You could use ngSwitch and ngSwitchCase directives like in navbar.component.html using a condition defined in your component see https://angular.io/api/common/NgSwitch

Alternatively, you can have a look at this pull request that implements jhiHasNotAuthority directive https://github.com/jhipster/generator-jhipster/pull/8371 it has not been merged into JHipster but it can help.

Also, you could find a more recent question with more details here: JHipster *jhiHasAnyAuthority directive check for "no authority"

Upvotes: 4

Related Questions