diff --git a/apps/meteor/app/livechat/server/startup.ts b/apps/meteor/app/livechat/server/startup.ts index b61c85c4001e..32cf01d2e640 100644 --- a/apps/meteor/app/livechat/server/startup.ts +++ b/apps/meteor/app/livechat/server/startup.ts @@ -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; } diff --git a/apps/meteor/client/meteorOverrides/login/saml.ts b/apps/meteor/client/meteorOverrides/login/saml.ts index f3ff7a8d45dd..14dfcc694e5c 100644 --- a/apps/meteor/client/meteorOverrides/login/saml.ts +++ b/apps/meteor/client/meteorOverrides/login/saml.ts @@ -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; } } diff --git a/apps/meteor/ee/server/startup/presence.ts b/apps/meteor/ee/server/startup/presence.ts index 0e7ba8a2b951..e0756e4b4c59 100644 --- a/apps/meteor/ee/server/startup/presence.ts +++ b/apps/meteor/ee/server/startup/presence.ts @@ -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(); }); diff --git a/apps/meteor/server/hooks/sauMonitorHooks.ts b/apps/meteor/server/hooks/sauMonitorHooks.ts index 74d45c7ba2de..3137ab41237a 100644 --- a/apps/meteor/server/hooks/sauMonitorHooks.ts +++ b/apps/meteor/server/hooks/sauMonitorHooks.ts @@ -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 },