I have defined a MudAppBar that contains AuthorizeView to hide a MudMenu when the user doesn't meet the policy ManagementPolicy (verifies if the user has at least one permission of a list), and others AuthorizeView to hide some options in the menu (with policies to verifies that the user has the specific permission in each option).
The problem I'm having is that the options inside the MudMenu are not rendering even if the policies are meet.
<MudAppBar Color="Color.Primary" Fixed="false" Class="">
@* The user meets this policy *@
<AuthorizeView Policy="ManagementPolicy" Context="management">
@* This MudMenu renders correctly *@
<MudMenu Class="d-none d-md-flex mud-text-primary px-2 h-100"
EndIcon="@Icons.Material.Filled.ArrowDropDown" AnchorOrigin="Origin.BottomCenter"
Label="@StringResource["Management"]">
@* The user meets this policy *@
<AuthorizeView Policy="@Permissions.ManageUsers">
@* This is not rendered *@
<MudListItem Href="users" IconColor="Color.Primary">
@StringResource["Users"]
</MudListItem>
</AuthorizeView>
@* This is rendered correctly *@
<MudListItem Href="users" IconColor="Color.Primary">
@StringResource["Users"]
</MudListItem>
@* The user meets this policy *@
<AuthorizeView Policy="@Permissions.ManageRoles">
@* This is not rendered *@
<MudListItem Href="users/roles" IconColor="Color.Primary">
@StringResource["Roles"]
</MudListItem>
</AuthorizeView>
</MudMenu>
</AuthorizeView>
</MudAppBar>
I found that supposedly can be done by using a Policy tag inside the AuthorizeView, but it doesn't exist, even after including the Microsoft.AspNetCore.Authorization.Policy namespace, where it was suppose to be defined.
The problem seems to apear when I started using MudBlazor; before that I was using simple html+bootstrap (with AuthorizedView in the same way), and it was rendering as expected.
Any idea what can I do or what I am missing?
I was able to solve this issue adding a CascadingAuthenticationState so the MudMenu component has access to the auth state. So after this modification, the menu renders as expected.
<MudAppBar Color="Color.Primary" Fixed="false" Class="">
<AuthorizeView Policy="ManagementPolicy" Context="management">
<MudMenu Class="d-none d-md-flex mud-text-primary px-2 h-100"
EndIcon="@Icons.Material.Filled.ArrowDropDown" AnchorOrigin="Origin.BottomCenter"
Label="@StringResource["Management"]">
@* This was added *@
<CascadingAuthenticationState>
<AuthorizeView Policy="@Permissions.ManageUsers">
<MudListItem Href="users" IconColor="Color.Primary">
@StringResource["Users"]
</MudListItem>
</AuthorizeView>
<MudListItem Href="users" IconColor="Color.Primary">
@StringResource["Users"]
</MudListItem>
<AuthorizeView Policy="@Permissions.ManageRoles">
<MudListItem Href="users/roles" IconColor="Color.Primary">
@StringResource["Roles"]
</MudListItem>
</AuthorizeView>
</CascadingAuthenticationState>
</MudMenu>
</AuthorizeView>
</MudAppBar>