Having an issue with how my Electron app is starting up. Very early into Accounts.onLogin() I’m calling the backend to get the stored values for the most important session variables in my app.
However, before this call is returned and the values are being assigned, the first element of my top navigation bar Template is already triggered.
As this navigation bar is dependent on one of the session variables, this is causing a race condition.
Is there a way how I can ensure that my Accounts.onLogin function is fully executed before the app starts to render Templates? I know this will lead to longer “time to paint” for the user but the current problems caused by the race conditions are worse.
Make elements in the navigation bar dependent on your var and not the whole bar or top level components, views, templates.
You can leave placeholders (invisible if needed) to not affect the navigation bar layout when components are missing.
Which should return false once the login process is complete. We use it in autoruns like this:
`if (Meteor.user() && !Meteor.loggingIn())``
(careful: Meteor.user() creates a reactive dependency on all fields of the user object. You can also only use Meteor.userId() for example if you don’t really need the whole object.)
Would this be the correct way (return false when the login isn’t finished)?
Template.navbarLogged.onCreated(function () {
if (Meteor.userId() && !Meteor.loggingIn()) {
console.warn(`navbar-logged.js: 161 - Template.navbarLogged.onCreated - login is finished`);
} else {
console.warn(`navbar-logged.js: 163 - Template.navbarLogged.onCreated - login is not finished`);
return;
}
I could also use a Session variable that is true once the code in the Accounts.onLogin() function has advanced far enough and then check that Session variable at the start of the Template.onCreated() - correct?
You’re not on blaze I think? Because otherwise, couldn’t you just use the {{ #unlessloggingIn }} template helper around your template?
ALSO:
Ah, hot tipp: To avoid the mess with the reactive variable, you could just stuff this in a template HELPER.
That’s reactive / wrapped in an autorun automatically & also it returns its current value. You could just stuff your if condition in a helper and call it a day.