Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: prevent destructuring _id of deleted users #32899

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading