feat(settings): log out all users after successful switch

This commit is contained in:
0xsysr3ll
2026-02-22 20:13:03 +01:00
parent c302b37b24
commit 7ecdfb4912
3 changed files with 39 additions and 13 deletions

View File

@@ -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.',
});
}

View File

@@ -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 ? (
<FormattedMessage
id="components.Settings.switchMediaServerDescriptionPlex"
defaultMessage="Have users link Jellyfin or Emby in {profile} => {linkedAccounts} first, then choose the target below and switch. Restart may be required."
defaultMessage="Have users link Jellyfin or Emby in {profile} => {linkedAccounts} first, then choose the target below and switch. All users will be logged out. Restart the server after switching."
values={{
profile: (
<strong className="font-semibold text-gray-300">Profile</strong>
@@ -56,7 +57,7 @@ const SwitchMediaServerSection = () => {
) : (
<FormattedMessage
id="components.Settings.switchMediaServerDescriptionJellyfinEmby"
defaultMessage="Configure Plex in the Plex tab, then have users link Plex in {profile} => {linkedAccounts}, then switch. This clears the current server. Restart may be required."
defaultMessage="Configure Plex in the Plex tab, then have users link Plex in {profile} => {linkedAccounts}, then switch. This clears the current server. All users will be logged out. Restart the server after switching."
values={{
profile: (
<strong className="font-semibold text-gray-300">Profile</strong>
@@ -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)

View File

@@ -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",