I have one address which I’d like to protect it from users who are not admin.
When typing the address in the address bar, the issue I have is that the client is not yet subscribed to the roles collection.
if(!Roles.userIsInRole(userId, 'admin')) { // here it is returning false as subscription is not done yet.
FlowRouter.go('/home'); /
return;
}
BlazeLayout.render('adminlayout', { main: 'adminpanel'});
}
});
How can I ensure that the subscription is done before checking for it?
Can’t remember where I got this code block from but it does the job:
// Pause FlowRouter until Roles information is ready
FlowRouter.wait();
Tracker.autorun(() => {
// if the roles subscription is ready, start routing
// there are specific cases that this reruns, so we also check
// that FlowRouter hasn't initalized already
if (Roles.subscription.ready() && !FlowRouter._initialized) {
FlowRouter.initialize();
}
});