From 810a4882cdcc8e2305fec6f118c27c69af0b187b Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 24 Mar 2020 10:58:45 -0300 Subject: [PATCH] Fix race conditions on or before login --- app/authorization/client/startup.js | 10 +++++++++- app/ui-sidenav/client/userPresence.js | 3 +++ app/webdav/client/startup/sync.js | 7 ++++--- client/lib/userData.js | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/authorization/client/startup.js b/app/authorization/client/startup.js index 99c1f06e760d..2edf696d2856 100644 --- a/app/authorization/client/startup.js +++ b/app/authorization/client/startup.js @@ -1,4 +1,5 @@ import { Meteor } from 'meteor/meteor'; +import { Tracker } from 'meteor/tracker'; import { hasAtLeastOnePermission } from './hasPermission'; import { CachedCollectionManager } from '../../ui-cached-collection'; @@ -28,5 +29,12 @@ Meteor.startup(() => { }, removed: (role) => Roles.remove({ _id: role.name }), }; - rolesStreamer.on('roles', (role) => events[role.type](role)); + + Tracker.autorun((c) => { + if (!Meteor.userId()) { + return; + } + rolesStreamer.on('roles', (role) => events[role.type](role)); + c.stop(); + }); }); diff --git a/app/ui-sidenav/client/userPresence.js b/app/ui-sidenav/client/userPresence.js index b079c0e632e6..e1df52380751 100644 --- a/app/ui-sidenav/client/userPresence.js +++ b/app/ui-sidenav/client/userPresence.js @@ -88,6 +88,9 @@ Tracker.autorun(() => { }); Template.userPresence.onRendered(function() { + if (!this.data || !this.data.uid) { + return; + } data.set(this.firstNode, this.data); if (featureExists) { return observer.observe(this.firstNode); diff --git a/app/webdav/client/startup/sync.js b/app/webdav/client/startup/sync.js index 5873da9672d1..c3547ee4bfe4 100644 --- a/app/webdav/client/startup/sync.js +++ b/app/webdav/client/startup/sync.js @@ -11,9 +11,10 @@ const events = { }; Tracker.autorun(async () => { - if (Meteor.userId()) { - const { accounts } = await APIClient.v1.get('webdav.getMyAccounts'); - accounts.forEach((account) => WebdavAccounts.insert(account)); + if (!Meteor.userId()) { + return; } + const { accounts } = await APIClient.v1.get('webdav.getMyAccounts'); + accounts.forEach((account) => WebdavAccounts.insert(account)); Notifications.onUser('webdav', ({ type, account }) => events[type](account)); }); diff --git a/client/lib/userData.js b/client/lib/userData.js index 87c45c2d34ac..6a3c5da44b84 100644 --- a/client/lib/userData.js +++ b/client/lib/userData.js @@ -9,7 +9,7 @@ export const isSyncReady = new ReactiveVar(false); function updateUser(userData) { const user = Users.findOne({ _id: userData._id }); - if (!user || userData._updatedAt > user._updatedAt.toISOString()) { + if (!user || !user._updatedAt || userData._updatedAt > user._updatedAt.toISOString()) { userData._updatedAt = new Date(userData._updatedAt); return Meteor.users.upsert({ _id: userData._id }, userData); }