diff --git a/app/lib/server/startup/userDataStream.js b/app/lib/server/startup/userDataStream.js index f30f745de500..b7c796d992ed 100644 --- a/app/lib/server/startup/userDataStream.js +++ b/app/lib/server/startup/userDataStream.js @@ -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 @@ -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 @@ -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); }, }; }; @@ -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 }) => { diff --git a/app/models/server/models/LoginServiceConfiguration.js b/app/models/server/models/LoginServiceConfiguration.js new file mode 100644 index 000000000000..8d3a31d6ee69 --- /dev/null +++ b/app/models/server/models/LoginServiceConfiguration.js @@ -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 });