Hi peeps, I’m having a problem trying to check for special permissions to access a route using the meteor-roles
package and React Router. The problem is, I’ve wrote a simpleB onEnter
hook to check if the currently logged in user has admin rights to access a route:
var adminArea = function (nextState, replace) {
if (!Meteor.user() || !Roles.userIsInRole(Meteor.userId(), ['admin'], Roles.GLOBAL_GROUP))
replace('/');
}
However, this check always fails and redirects me to the homepage, even if the currently logged in user has admin rights. Because the current user has not been fetched from the database yet, and Meteor.user()
returns undefined
. I’ve also tried to do the same thing from a component but I’m having the same problem. Usually, facing this kind of problem on a more traditional app, I’d provide a callback or listen to some event. How do I get around this situation in this case?