diff --git a/packages/client/src/pages/PortalSettings/categories/security/sessions/index.js b/packages/client/src/pages/PortalSettings/categories/security/sessions/index.js index 74dce3c90c..a63e93137f 100644 --- a/packages/client/src/pages/PortalSettings/categories/security/sessions/index.js +++ b/packages/client/src/pages/PortalSettings/categories/security/sessions/index.js @@ -97,6 +97,8 @@ const Sessions = ({ setLogoutDialogVisible, setLogoutAllDialogVisible, removeSession, + removeAllActiveSessionsById, + removeAllExceptThisEventId, }) => { const [isLoading, setIsLoading] = useState(false); @@ -131,24 +133,34 @@ const Sessions = ({ currentDeviceType, }); - const onClickRemoveAllSessions = () => { + const onClickLogoutAllSessions = async () => { try { setIsLoading(true); - console.log("onClickRemoveAllSessions"); + await removeAllActiveSessionsById(connections[0]?.userId); + setConnections([]); + await fetchData(); + toastr.success("Successfully logout all sessions"); } catch (error) { - toastr.error(error); + toastr.error("The user is already logged out"); } finally { setIsLoading(false); setLogoutAllDialogVisible(false); } }; - const onClickRemoveAllExceptThis = () => { + const onClickLogoutAllExceptThis = async (id) => { try { setIsLoading(true); - console.log("onClickRemoveAllExceptThis"); + await removeAllExceptThisEventId(connections[0]?.id); + + const filteredConnections = connections.filter( + (connection) => connection.id === id, + ); + setConnections(filteredConnections); + await fetchData(); + toastr.success("Successfully logout except this"); } catch (error) { - toastr.error(error); + toastr.error("The user is already logged out"); } finally { setIsLoading(false); setLogoutAllDialogVisible(false); @@ -169,7 +181,7 @@ const Sessions = ({ (connection) => connection.id !== id, ); setConnections(filteredConnections); - fetchData(); + await fetchData(); toastr.success( t("Profile:SuccessLogout", { platform: foundConnection.platform, @@ -187,6 +199,7 @@ const Sessions = ({ // console.log("allSessions", JSON.parse(JSON.stringify(allSessions))); // console.log("sessionsData", JSON.parse(JSON.stringify(sessionsData))); // console.log("connections", JSON.parse(JSON.stringify(connections))); + // console.log("userLastSession", JSON.parse(JSON.stringify(userLastSession))); return ( @@ -233,10 +246,11 @@ const Sessions = ({ t={t} visible={logoutAllDialogVisible} isLoading={isLoading} + connections={connections} displayName={displayName} onClose={() => setLogoutAllDialogVisible(false)} - onRemoveAllSessions={onClickRemoveAllSessions} - onRemoveAllExceptThis={onClickRemoveAllExceptThis} + onLogoutAllSessions={onClickLogoutAllSessions} + onLogoutAllExceptThis={onClickLogoutAllExceptThis} /> )} @@ -269,6 +283,8 @@ export default inject(({ settingsStore, setup, peopleStore }) => { setLogoutDialogVisible, setLogoutAllDialogVisible, removeSession, + removeAllActiveSessionsById, + removeAllExceptThisEventId, } = setup; return { @@ -294,6 +310,8 @@ export default inject(({ settingsStore, setup, peopleStore }) => { setLogoutDialogVisible, setLogoutAllDialogVisible, removeSession, + removeAllActiveSessionsById, + removeAllExceptThisEventId, }; })( withTranslation(["Settings", "Profile", "Common", "ChangeUserStatusDialog"])( diff --git a/packages/client/src/store/SettingsSetupStore.js b/packages/client/src/store/SettingsSetupStore.js index 700fd77811..e9e07e9274 100644 --- a/packages/client/src/store/SettingsSetupStore.js +++ b/packages/client/src/store/SettingsSetupStore.js @@ -557,6 +557,10 @@ class SettingsSetupStore { return api.settings.removeAllActiveSessionsById(userId); }; + removeAllExceptThisEventId = (userId) => { + return api.settings.removeAllExceptThisEventId(userId); + }; + removeAllSessions = () => { return api.settings.removeAllActiveSessions(); }; diff --git a/packages/shared/api/settings/index.ts b/packages/shared/api/settings/index.ts index b20512afd5..6e99d8f881 100644 --- a/packages/shared/api/settings/index.ts +++ b/packages/shared/api/settings/index.ts @@ -912,6 +912,14 @@ export function removeAllActiveSessionsById(userId) { }); } +export function removeAllExceptThisEventId(eventId) { + return request({ + method: "put", + url: `/security/activeconnections/logoutallexceptthis/${eventId}`, + data: { eventId }, + }); +} + export function removeAllActiveSessions() { return request({ method: "put",