Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useStream, useSessionDispatch } from '@rocket.chat/ui-contexts';
import { Meteor } from 'meteor/meteor';
import { useEffect } from 'react';

export const useForceLogout = (userId: string) => {
Expand All @@ -9,13 +8,7 @@ export const useForceLogout = (userId: string) => {
useEffect(() => {
setForceLogout(false);

const unsubscribe = getNotifyUserStream(`${userId}/force_logout`, (sessionId) => {
const currentSessionId = Meteor.connection._lastSessionId;

if (sessionId === currentSessionId) {
window.location.reload();
}

const unsubscribe = getNotifyUserStream(`${userId}/force_logout`, () => {
setForceLogout(true);
});

Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/definition/externals/meteor/meteor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ declare module 'meteor/meteor' {
}

const server: {
sessions: Map<string, { userId: string; heartbeat: DDPCommon.Heartbeat }>;
sessions: Map<string, { userId: string; heartbeat: DDPCommon.Heartbeat; connectionHandle: Meteor.Connection }>;
publish_handlers: {
meteor_autoupdate_clientVersions(): void;
};
Expand Down Expand Up @@ -118,7 +118,6 @@ declare module 'meteor/meteor' {
},
]
): SubscriptionHandle;
_lastSessionId: string;

call(methodName: string, ...args: [...unknown, callback?: (error: Error | null, result: unknown) => void]): void;
}
Expand Down
5 changes: 5 additions & 0 deletions apps/meteor/server/modules/listeners/listeners.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { IUser, IRoom, IRole, VideoConference, ISetting, IOmnichannelRoom }
import { Logger } from '@rocket.chat/logger';
import type { ServerMediaSignal } from '@rocket.chat/media-signaling';
import { parse } from '@rocket.chat/message-parser';
import { Meteor } from 'meteor/meteor';

import { settings } from '../../../app/settings/server/cached';
import type { NotificationsModule } from '../notifications/notifications.module';
Expand Down Expand Up @@ -48,6 +49,10 @@ export class ListenersModule {

service.onEvent('user.forceLogout', (uid: string, sessionId?: string) => {
notifications.notifyUserInThisInstance(uid, 'force_logout', sessionId);
if (sessionId) {
const sessions = Meteor.server.sessions.get(sessionId);
sessions?.connectionHandle.close();
}
});

service.onEvent('notify.ephemeralMessage', (uid, rid, message) => {
Expand Down
Loading