I get response from an api regarding user roles, if user has one role, I get single value place holder i.e
{
"nameid": "1",
"unique_name": "Anees",
"role": "Student",
"nbf": 1587681052,
"exp": 1587767452,
"iat": 1587681052
}
If user has more than one roles, roles consider as array ie.
{
"nameid": "2",
"unique_name": "Naveed",
"role": [
"SuperAdmin",
"Admin",
"Teacher",
"Clerk",
"Student"
],
"nbf": 1587712850,
"exp": 1587799250,
"iat": 1587712850
}
How can I handle both a single value and a collection in same place holder?
This script work fit for me
const userRoles = this.decodedToken.role as Array<string>;
I have to use some collection methods like find etc
var status = userRoles.find(x => x == role);
it gives error in case of single value.
Any solution, please.