Hi all,
I try to call a synchronize method if a user reconnects to my webapp, i.e. when he didn’t press logout button and later revisits the site. I tried to tackle this in the startup function as follows:
if (Meteor.isClient) {
Meteor.startup(function () {
if (Meteor.user() != null) {
console.log('synchronizing now');
Session.set('isSynchronizing', true);
Meteor.call('synchronize', function(error, result){
if (error) {
alert(error);
}
});
} else {
console.log('not synchronizing');
}
...
The problem is that sometimes Meteor.user() != null
evaluates to true and sometimes to false. So, refreshing the page sometimes triggers the synchronization and sometimes not. I suspect a race condition going on.
Any ideas on how to deterministically call the synchronization method whenever a user revisits the application?
With kind regards,
Koen