From 7ecdfb4912afb15f27e4cc4d70874296cffeb071 Mon Sep 17 00:00:00 2001 From: 0xsysr3ll <0xsysr3ll@pm.me> Date: Sun, 22 Feb 2026 20:13:03 +0100 Subject: [PATCH] feat(settings): log out all users after successful switch --- server/routes/settings/index.ts | 31 ++++++++++++++++--- .../Settings/SwitchMediaServerSection.tsx | 19 +++++++----- src/i18n/locale/en.json | 2 +- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/server/routes/settings/index.ts b/server/routes/settings/index.ts index 592858add..2515fe7c3 100644 --- a/server/routes/settings/index.ts +++ b/server/routes/settings/index.ts @@ -8,6 +8,7 @@ import { UserType } from '@server/constants/user'; import { getRepository } from '@server/datasource'; import Media from '@server/entity/Media'; import { MediaRequest } from '@server/entity/MediaRequest'; +import { Session } from '@server/entity/Session'; import { User } from '@server/entity/User'; import { Watchlist } from '@server/entity/Watchlist'; import type { PlexConnection } from '@server/interfaces/api/plexInterfaces'; @@ -504,11 +505,16 @@ settingsRoutes.post( .where("watchlist.ratingKey != ''") .execute(); await settings.save(); + await getRepository(Session) + .createQueryBuilder() + .delete() + .from(Session) + .execute(); startJobs(); return res.status(200).json({ message: useEmby - ? 'Switched to Emby. Restart or reload if the app does not update.' - : 'Switched to Jellyfin. Restart or reload if the app does not update.', + ? 'Switched to Emby. All users have been logged out. Restart the server, then sign in with the new media server.' + : 'Switched to Jellyfin. All users have been logged out. Restart the server, then sign in with the new media server.', }); } else if ( current === MediaServerType.JELLYFIN || @@ -561,10 +567,15 @@ settingsRoutes.post( ) .execute(); await settings.save(); + await getRepository(Session) + .createQueryBuilder() + .delete() + .from(Session) + .execute(); startJobs(); return res.status(200).json({ message: - 'Switched to Jellyfin. Reconfigure the server and have users sign in again. Restart or reload if the app does not update.', + 'Switched to Jellyfin. All users have been logged out. Restart the server, then reconfigure and sign in with the new media server.', }); } @@ -609,10 +620,15 @@ settingsRoutes.post( ) .execute(); await settings.save(); + await getRepository(Session) + .createQueryBuilder() + .delete() + .from(Session) + .execute(); startJobs(); return res.status(200).json({ message: - 'Switched to Emby. Reconfigure the server and have users sign in again. Restart or reload if the app does not update.', + 'Switched to Emby. All users have been logged out. Restart the server, then reconfigure and sign in with the new media server.', }); } @@ -657,10 +673,15 @@ settingsRoutes.post( ) .execute(); await settings.save(); + await getRepository(Session) + .createQueryBuilder() + .delete() + .from(Session) + .execute(); startJobs(); return res.status(200).json({ message: - 'Switched to Plex. Restart or reload if the app does not update.', + 'Switched to Plex. All users have been logged out. Restart the server, then sign in with the new media server.', }); } diff --git a/src/components/Settings/SwitchMediaServerSection.tsx b/src/components/Settings/SwitchMediaServerSection.tsx index ca37d757d..6fb8ee271 100644 --- a/src/components/Settings/SwitchMediaServerSection.tsx +++ b/src/components/Settings/SwitchMediaServerSection.tsx @@ -13,7 +13,8 @@ type SwitchTargetServerType = 'jellyfin' | 'emby'; const messages = defineMessages('components.Settings', { switchMediaServerError: 'Something went wrong while switching media server. Please try again.', - switchMediaServerSuccess: 'Media server cleared. You may need to restart.', + switchMediaServerSuccess: + 'Media server switched. All users logged out. Restart the server, then sign in again.', }); const SwitchMediaServerSection = () => { @@ -41,7 +42,7 @@ const SwitchMediaServerSection = () => { {settings.currentSettings.mediaServerType === MediaServerType.PLEX ? ( Profile @@ -56,7 +57,7 @@ const SwitchMediaServerSection = () => { ) : ( Profile @@ -101,15 +102,19 @@ const SwitchMediaServerSection = () => { confirmText={intl.formatMessage(globalMessages.areyousure)} onClick={async () => { try { - await axios.post( + const { data } = await axios.post<{ message?: string }>( '/api/v1/settings/switch-media-server', settings.currentSettings.mediaServerType === MediaServerType.PLEX ? { targetServerType: switchTargetServerType } : undefined ); - addToast(intl.formatMessage(messages.switchMediaServerSuccess), { - appearance: 'success', - }); + addToast( + data?.message ?? + intl.formatMessage(messages.switchMediaServerSuccess), + { + appearance: 'success', + } + ); window.location.reload(); } catch (err: unknown) { const extracted = axios.isAxiosError(err) diff --git a/src/i18n/locale/en.json b/src/i18n/locale/en.json index a78fcad17..47769b7b1 100644 --- a/src/i18n/locale/en.json +++ b/src/i18n/locale/en.json @@ -1284,7 +1284,7 @@ "components.Settings.startscan": "Start Scan", "components.Settings.starttyping": "Starting typing to search.", "components.Settings.switchMediaServerError": "Something went wrong while switching media server. Please try again.", - "components.Settings.switchMediaServerSuccess": "Media server cleared. You may need to restart.", + "components.Settings.switchMediaServerSuccess": "Media server switched. All users logged out. Restart the server, then sign in again.", "components.Settings.syncJellyfin": "Sync Libraries", "components.Settings.syncing": "Syncing", "components.Settings.tautulliApiKey": "API Key",