Can someone assist me in figuring out the best way to check for admin role using a component in Angular?
Below is the code snippet from the component:
checkIfIsAdmin(): any {
let user_string = localStorage.getItem("currentUser");
if (!isNullOrUndefined([user_string])) {
console.log(user_string);
return true;
} else {
return null;
}
}
I am trying to verify the ROLE_ADMIN
that I receive in the following format:
{
"longId": 4,
"name": "bbb",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="45272727052228242c296b2628">[email protected]</a>",
"userName": "bbb",
"token": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI0IiwiaWF0IjoxNTU5NDk0NTczLCJleHAiOjE1NTk0OTQ4NzN9.XmSHywZv09b4BR9-NxyCTVPF33pLsk3QtTEXQMQF4YHW7i27Ghj2Uh3WZAegpG4rdSImKcm1wMgJsPLpHcTyew",
"roles": [
"ROLE_USER",
"ROLE_ADMIN"
]
}
I am unsure about how to iterate through roles within the if
condition, can you please guide me on this?