You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;
}
`
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
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;
}
`
The text was updated successfully, but these errors were encountered: