-
Notifications
You must be signed in to change notification settings - Fork 97
Open
Description
Hello, not sure if I'm using the GetRolesAsync() incorrectly.
Code repo
Apologies for the formatting of this post. Can't seem to get it all in the code block.
`
bool CheckIfUserIsSuperAdmin(ApplicationUser user)
{
if (user is not null)
{
List rolesIDsList = user.Roles;
foreach (var roleId in rolesIDsList)
{
Task<ApplicationRole?> roleTask = _RoleManager.FindByIdAsync(roleId);
roleTask.Wait();
if(roleTask.Result is not null)
{
ApplicationRole role = roleTask.Result;
if (role.Name!.Equals(Constants.SUPERADMIN))
{
//return true; // this works - BUT commenting it out to allow code below to run.
break;
}
}
}
// BELOW CODE DOES NOT WORK
Task<IList<string>> rolesListResult = _UserManager.GetRolesAsync(user); // HANGS here
rolesListResult.Wait();
if (rolesListResult.Result is not null)
{
IList<string> roles = rolesListResult.Result;
if(roles.Contains(Constants.SUPERADMIN))
{
return true;
}
}
}
return false;
}
`
Metadata
Metadata
Assignees
Labels
No labels