I am unable to access the neededPermissions array in the routes. I clearly have the array neededPermissions in routes but every time I try to access the array, console logs undefined.
How can I get the neededPermissions array from the meta object in routes? Clearly to.meta.neededPermissions prints undefined, which make's it impossible to loop through currentUser.
{
path: "/administration",
name: "Administration",
component: PageAdministration,
meta: {
requiresAuth: true,
neededPermissions: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
},
}
function to authorize users
console.log(to.meta.neededPermissions );
if(currentUser!==null && to.meta.neededPermissions !== undefined)
{
for(let i = 0;i<currentUser.teams.length;i++){
const team = currentUser.teams[i]
const validPermissions = team.permissions.filter((item) => { return to.meta.neededPermissions.includes(item.permissionType); });
const mappedValidPermissions = validPermissions.map((item) => { return item.permissionType; });
if (!to.meta.neededPermissions.every(i=>mappedValidPermissions.includes(i))) {
isAllowed = false;
next({ path: "/:notFound(.*)" });
break;
}
} if(isAllowed) next();
}
console.log(to.meta.neededPermissions), but as far as I can see only one route (/administration) providesmeta.neededPermissions. My guess is that you have some other route initially loading trying to call this function which doesn't have the same meta properties provided.to.meta.neededPermissionsbeing undefined is expected. are you trying to have the if statement be true for other situations?