meteor-roles: userIsInRole return value is unpredictable is called in flow-router triggersEnter callback

Sample code:

var adminRoutesGroup = FlowRouter.group({
  prefix: '/admin',
  triggersEnter: [
    function(path, redirect) {
      console.warn('Meteor.userId()', Meteor.userId());
      console.warn('Roles.userIsInRole(Meteor.userId(), [admin])', Roles.userIsInRole(Meteor.userId(), ['admin']));
      return !Roles.userIsInRole(Meteor.userId(), ['admin']) ? redirect(....) : null;
    }
  ]
});

With same Meteor.userId(), I have Roles.userIsInRole(Meteor.userId(), ['admin']) => true for Chrome and false for Firefox or mobile Safari.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 21 (12 by maintainers)

Most upvoted comments

For anyone else reading this, using a timeout is not the recommended approach. As Arunoda points out in the FlowRouter docs, performing checks that rely on subscription data in the route is an anti-pattern and results in a poor user experience.

For the proper way to do this, please see: