Is there any reason why this doesn’t happen already via the Accounts package?
I previously used fast-render but now that package is so old it crashes my app when I add it.
Does anyone know if there is another package that does something similar?
My issue is I am using React Router and I have protected routes for logged in users only & admin routes for admin users.
The routes are loaded on Meteor.startup() and the Meteor.user() object is not available at startup and those routes bounce the user to the home page via <Redirect>.
Also happy to hear of other innovative ways around the issue…
Try to handle all your routes in a different file or component, u can call it for example App. After that u just have to render <App /> inside your Meteor.sartup(). If u want to load user collection, u can do it with withTracker to create a container inside App.
The reason is that only the user’s _id is stored in the session. All other data is destroyed on refresh and re-fetched from the server.
There are 2 ways to solve it:
Store user data required to do your authorization as part of a persistent session. This requires you to manually remove that data on logout. Actually there is a great package for that although i’m not sure if they still maintain it: https://atmospherejs.com/u2622/persistent-session. This allows you to set session data for as long as the user is authenticated.
Wait with your system until the userData subscription has finished. This means that you subscribe to the data, store a status of this subscription somewhere and show a loading icon until the subscription finished. (Note that you can do this by tracking Meteor.user() reactively and base that status on that, but when something goes wrong you will not be able to remove the spinner)
Yeah that worked great.
I just put a simple component in the startup which loaded my main component with routes and all.
I will post my code later in case anyone else wants to copy.