Skip to content

HasPermission on Web Api #1

@meliora-solution

Description

@meliora-solution

user.HasPermission(UserPermissions.PermissonName) is not a problem in UserManagement project but is not working for EasyStock which use http to connect to web api project to to get the data.

Another approach to solve is below. It is working but it is a little bit slow.

// Fetch permissions during initialization or when needed
var result = await httpClient.GetAsync("api/Authenticate/getuserpermissions");

if (result.IsSuccessStatusCode)
{
    var contentTemp = await result.Content.ReadAsStringAsync();
    roles = JsonConvert.DeserializeObject<List<string>>(contentTemp);
}

// Use roles in your conditional checks - NavMenu 
@if (roles != null && roles.Contains("AccessPageLevelOne"))
{
    <FluentNavLink Href="contactList" Icon="@(new Icons.Regular.Size20.WeatherPartlyCloudyDay())" IconColor="Color.Accent">Contact List</FluentNavLink>
    <FluentNavLink Href="contactCreate" Icon="@(new Icons.Regular.Size20.WeatherPartlyCloudyDay())" IconColor="Color.Accent">EasyStock Contact</FluentNavLink>
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions