How to wait until subscribed to Roles? (FlowRouter)

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.

So I have something like :

FlowRouter.route(’/admin’, {
name: ‘adminpanel’,
action(params, queryParams) {
const userId = Meteor.userId();

if(!Roles.userIsInRole(userId, 'admin')) { // here it is returning false as subscription is not done yet.
  FlowRouter.go('/home'); /
BlazeLayout.render('adminlayout', { main: 'adminpanel'});


How can I ensure that the subscription is done before checking for it?

Using meteor 1.8.3.

1 Like

I would recommend using FlowRouter Extra and the waitOn hook

Can’t remember where I got this code block from but it does the job:

// Pause FlowRouter until Roles information is ready
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) {

I installed FlowRouter Extra and the mehod waitOn wasn’t even called. I assume I did something wrong.

It worked perfectly. Thanks a lot and Merry Xmas.

1 Like

This code lines might come from
There’s another good post about this issue here

1 Like