Skip to content

Commit

Permalink
chore: prevent destructuring _id of deleted users (#32899)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Jul 25, 2024
1 parent cb88ca8 commit 7442ffc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Meteor.startup(async () => {
});

// Remove when accounts.onLogout is async
Accounts.onLogout(({ user }: { user: IUser }) => {
Accounts.onLogout(({ user }: { user?: IUser }) => {
if (!user?.roles?.includes('livechat-agent') || user?.roles?.includes('bot')) {
return;
}
Expand Down
6 changes: 6 additions & 0 deletions apps/meteor/client/meteorOverrides/login/saml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ declare module 'meteor/accounts-base' {
credentialToken?: string;
credentialSecret?: string;
};

/**
* There is one case where the onlogout event is triggered with no user:
* during the deletion, the user is logged out, and the framework try to get the user from the database.
*/
function onLogout(func: (options: { user?: Meteor.User; connection: Meteor.Connection }) => void): void;
}
}

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/ee/server/startup/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Meteor.startup(() => {
})();
});

Accounts.onLogout((login: any): void => {
void Presence.removeConnection(login.user._id, login.connection.id, nodeId);
Accounts.onLogout((login): void => {
void Presence.removeConnection(login.user?._id, login.connection.id, nodeId);

updateConns();
});
Expand Down
5 changes: 4 additions & 1 deletion apps/meteor/server/hooks/sauMonitorHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ Accounts.onLogin((info: ILoginAttempt) => {
deviceManagementEvents.emit('device-login', eventObject);
});

Accounts.onLogout((info: { user: Meteor.User; connection: Meteor.Connection }) => {
Accounts.onLogout((info) => {
const { httpHeaders } = info.connection;

if (!info.user) {
return;
}
sauEvents.emit('accounts.logout', {
userId: info.user._id,
connection: { instanceId: InstanceStatus.id(), ...info.connection, httpHeaders: httpHeaders as IncomingHttpHeaders },
Expand Down

0 comments on commit 7442ffc

Please sign in to comment.