Skip to content

Commit

Permalink
Regression: Fix login screen reactivity of external login providers (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok authored Sep 28, 2020
1 parent 7a7a5e8 commit 2ee3bc4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/lib/server/startup/userDataStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MongoInternals } from 'meteor/mongo';

import { Users } from '../../../models/server';
import { Notifications } from '../../../notifications/server';
import loginServiceConfiguration from '../../../models/server/models/LoginServiceConfiguration';

let processOnChange;
// eslint-disable-next-line no-undef
Expand All @@ -10,6 +11,7 @@ const disableOplog = Package['disable-oplog'];
if (disableOplog) {
// Stores the callbacks for the disconnection reactivity bellow
const userCallbacks = new Map();
const serviceConfigCallbacks = new Set();

// Overrides the native observe changes to prevent database polling and stores the callbacks
// for the users' tokens to re-implement the reactivity based on our database listeners
Expand All @@ -32,11 +34,17 @@ if (disableOplog) {
userCallbacks.set(selector._id, cbs);
}
}

if (collectionName === 'meteor_accounts_loginServiceConfiguration') {
serviceConfigCallbacks.add(callbacks);
}

return {
stop() {
if (cbs) {
cbs.delete(callbacks);
}
serviceConfigCallbacks.delete(callbacks);
},
};
};
Expand All @@ -57,6 +65,23 @@ if (disableOplog) {
}
}
};

loginServiceConfiguration.on('change', ({ clientAction, id, data, diff }) => {
switch (clientAction) {
case 'inserted':
case 'updated':
const record = { ...data || diff };
delete record.secret;
serviceConfigCallbacks.forEach((callbacks) => {
callbacks[clientAction === 'inserted' ? 'added' : 'changed']?.(id, record);
});
break;
case 'removed':
serviceConfigCallbacks.forEach((callbacks) => {
callbacks.removed?.(id);
});
}
});
}

Users.on('change', ({ clientAction, id, data, diff }) => {
Expand Down
7 changes: 7 additions & 0 deletions app/models/server/models/LoginServiceConfiguration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ServiceConfiguration } from 'meteor/service-configuration';

import { Base } from './_Base';

export class LoginServiceConfiguration extends Base {}

export default new LoginServiceConfiguration(ServiceConfiguration.configurations, { preventSetUpdatedAt: true });

0 comments on commit 2ee3bc4

Please sign in to comment.