I am trying to implement alanning Meteor roles with a reactive router in my Meteor application. Everything works fine, except that I cannot properly manage traffic using the alanning or Meteor.user() roles
I tried with the meteor role:
I am trying to use onEnter={requireVerified} on my route. This is the code:
const requireVerified = (nextState, replace) => { if (!Roles.userIsInRole(Meteor.userId(), ['verified'],'user_default')) { replace({ pathname: '/account/verify', state: { nextPathname: nextState.location.pathname }, }); } };
I tried to use Meteor.user ():
const requireVerified = (nextState, replace) => { if (!Meteor.user().isverified == true) { replace({ pathname: '/account/verify', state: { nextPathname: nextState.location.pathname }, }); } };
So this works when I click on the route link, but when I update manually (F5), it does not work. After that, I found that Meteor.user() not ready when I manually refresh the page.
I know that Meteor.userid () or Meteor.logginIn () work, but I wanted to check not only that they are registered, but also if they are "checked" or play a role.
I also tried to check inside the component with the reaction componentDidMount() or componentWillMount() , in both cases it is the same, manual fresh does not load Meteor.user() before the container is installed.
So, what is the best way to restrict components / routes using meteorite / alaning roles + react to the router? (I use reactive composter inside TheMeteorChef base)
Thanks.
reactjs meteor react-router
NOaMTL
source share