Reputation: 709
I'm using FlowRouter with the alanning:roles package to check on every routeEnter for a certain route group if the user has the role as an admin.
let adminRoutes = FlowRouter.group({
name: "adminRoutes",
triggersEnter: [checkAdmin]
});
checkAdmin = () => {
console.log(Roles.userIsInRole(Meteor.userId(), 'admin')); // false
if (! Roles.userIsInRole(Meteor.userId(), 'admin')) {
console.log(Roles.userIsInRole(Meteor.userId(), 'admin')); //false
FlowRouter.redirect('/notFound');
}
};
When i log in as an admin the console log is first false and i get redirected to the notFound page. When i hit the back-button it seems the role is initialised and i can actually see the admin area.
How can i avoid this delay in initialising the admin role?
Thanks for your help!
Muff
Upvotes: 1
Views: 95
Reputation: 20226
The user object takes a few cycles to be fully loaded so if you check it immediately you won't have access to all the user's properties. It's best to show a spinner while waiting for the user object to be loaded. You can create a subscription to the user that includes only those keys you really need and wait for that subscription to be ready.
Upvotes: 1