i have an app component that is rendering correctly with react router, but now i’m having trouble with checking if user is logged and redirecting to the /signin route, here’s the code i added to the app component:
componentWillMount() {
if (!Meteor.user()) {
browserHistory.push('/signin');
}
}
it works only when there’s no account, but when the user is logged it stills redirects to the signin route
IMHO your router’s only job should be to route, and it should not have to worry about users or subscriptions.
You should do that in your app’s global container. So the flow should be:
Wait for current user and any other global subscription to be done loading.
Load the app.
Load the component.
Now you know the current user will be available to your component (I use React’s context to access it but there are other ways), and your router can remain “dumb”.
makes sense, do you have an example of that flow to check it out ? i’m having trouble with checking that on the container as sometimes it runs the function while logging in some other times afterwards so it’s not consistent, also React docs advice not to use context =/
If you don’t want to use context you can check out how Mantra does it:
But personally I think using context is fine, even if you do end up having to refactor it one day it’s worth it for the time you’ll save now compared to other, more complex patterns.