Hi,
I’m currently trying to check to see if the user fits a role, if not send them to another page. The problem is that I get undefined for Meteor users. I login in on a seperate page and the callback shows me logged in. Not sure why - I feel like its a race condition (The meteor accounts is not ready yet) or I need to do a mixin but not sure how to do that in something thats not a class. Any thoughts?
My Router Code:
AppRoutes = (
/reversedarrow >Router >
/reversedarrow >Route path="/" component={App}>
/reversedarrow >IndexRoute component={Home} />
/reversedarrow >Route path="/admin" component={Admin} />
/reversedarrow >Route path="/login" component={Login} />
/reversedarrow >Route path="/dealerPortal" component={dealerPortal} onEnter={requireAuth} />
/reversedarrow >/Route>
/slreversedarrow >/Router>
);
ReactRouterSSR.Run(AppRoutes);
My onEnter Code:
function requireAuth(nextState, replaceState) {
console.log("HELLO");
console.log(Meteor.user());
console.log(Meteor.loggingIn());
if(Meteor.user() != undefined) {
if (Meteor.user().roles['default-group'][0] == 'dealer') {
} else {
replaceState({ nextPathname: nextState.location.pathname }, '/login')
}
} else {
replaceState({ nextPathname: nextState.location.pathname }, '/login')
}
}