diff --git a/server/routes/user/usersettings.ts b/server/routes/user/usersettings.ts index 302c7407d..96a746ce4 100644 --- a/server/routes/user/usersettings.ts +++ b/server/routes/user/usersettings.ts @@ -336,8 +336,14 @@ userSettingsRoutes.delete<{ id: string }>( '/linked-accounts/plex', isOwnProfileOrAdmin(), async (req, res, next) => { + const settings = getSettings(); const userRepository = getRepository(User); + // Make sure Plex login is enabled + if (settings.main.mediaServerType !== MediaServerType.PLEX) { + return res.status(500).json({ error: 'Plex login is disabled' }); + } + try { const user = await userRepository.findOne({ where: { id: Number(req.params.id) }, @@ -393,8 +399,11 @@ userSettingsRoutes.post<{ username: string; password: string }>( return next({ status: 401, message: 'Unauthorized' }); } // Make sure jellyfin login is enabled - if (settings.main.mediaServerType !== MediaServerType.JELLYFIN) { - return res.status(500).json({ error: 'Jellyfin login is disabled' }); + if ( + settings.main.mediaServerType !== MediaServerType.JELLYFIN && + settings.main.mediaServerType !== MediaServerType.EMBY + ) { + return res.status(500).json({ error: 'Jellyfin/Emby login is disabled' }); } // Do not allow linking of an already linked account @@ -404,8 +413,7 @@ userSettingsRoutes.post<{ username: string; password: string }>( }) ) { return res.status(422).json({ - error: - 'The specified Jellyfin account is already linked to a Jellyseerr user', + error: 'The specified account is already linked to a Jellyseerr user', }); } @@ -440,15 +448,17 @@ userSettingsRoutes.post<{ username: string; password: string }>( }) ) { return res.status(422).json({ - error: - 'The specified Jellyfin account is already linked to a Jellyseerr user', + error: 'The specified account is already linked to a Jellyseerr user', }); } const user = req.user; // valid jellyfin user found, link to current user - user.userType = UserType.JELLYFIN; + user.userType = + settings.main.mediaServerType === MediaServerType.EMBY + ? UserType.EMBY + : UserType.JELLYFIN; user.jellyfinUserId = account.User.Id; user.jellyfinUsername = account.User.Name; user.jellyfinAuthToken = account.AccessToken; @@ -457,7 +467,7 @@ userSettingsRoutes.post<{ username: string; password: string }>( return res.status(204).send(); } catch (e) { - logger.error('Failed to link Jellyfin account to user.', { + logger.error('Failed to link account to user.', { label: 'API', ip: req.ip, error: e, @@ -478,8 +488,17 @@ userSettingsRoutes.delete<{ id: string }>( '/linked-accounts/jellyfin', isOwnProfileOrAdmin(), async (req, res, next) => { + const settings = getSettings(); const userRepository = getRepository(User); + // Make sure jellyfin login is enabled + if ( + settings.main.mediaServerType !== MediaServerType.JELLYFIN && + settings.main.mediaServerType !== MediaServerType.EMBY + ) { + return res.status(500).json({ error: 'Jellyfin/Emby login is disabled' }); + } + try { const user = await userRepository.findOne({ where: { id: Number(req.params.id) }, diff --git a/src/components/UserProfile/UserSettings/UserLinkedAccountsSettings/LinkJellyfinModal.tsx b/src/components/UserProfile/UserSettings/UserLinkedAccountsSettings/LinkJellyfinModal.tsx index 564a95f9c..a9a99cc71 100644 --- a/src/components/UserProfile/UserSettings/UserLinkedAccountsSettings/LinkJellyfinModal.tsx +++ b/src/components/UserProfile/UserSettings/UserLinkedAccountsSettings/LinkJellyfinModal.tsx @@ -5,6 +5,7 @@ import { useUser } from '@app/hooks/useUser'; import { RequestError } from '@app/types/error'; import defineMessages from '@app/utils/defineMessages'; import { Transition } from '@headlessui/react'; +import { MediaServerType } from '@server/constants/server'; import { Field, Form, Formik } from 'formik'; import { useState } from 'react'; import { useIntl } from 'react-intl'; @@ -13,17 +14,18 @@ import * as Yup from 'yup'; const messages = defineMessages( 'components.UserProfile.UserSettings.LinkJellyfinModal', { - title: 'Link Jellyfin Account', + title: 'Link {mediaServerName} Account', description: - 'Enter your Jellyfin credentials to link your account with Jellyseerr.', + 'Enter your {mediaServerName} credentials to link your account with {applicationName}.', username: 'Username', password: 'Password', usernameRequired: 'You must provide a username', passwordRequired: 'You must provide a password', saving: 'Adding…', save: 'Link', - errorUnauthorized: 'Unable to connect to Jellyfin using your credentials', - errorExists: 'This account is already linked to a Jellyseerr user', + errorUnauthorized: + 'Unable to connect to {mediaServerName} using your credentials', + errorExists: 'This account is already linked to a {applicationName} user', errorUnknown: 'An unknown error occurred', } ); @@ -53,6 +55,12 @@ const LinkJellyfinModal: React.FC = ({ ), }); + const applicationName = settings.currentSettings.applicationTitle; + const mediaServerName = + settings.currentSettings.mediaServerType === MediaServerType.EMBY + ? 'Emby' + : 'Jellyfin'; + return ( = ({ onSave(); } catch (e) { if (e instanceof RequestError && e.status == 401) { - setError(intl.formatMessage(messages.errorUnauthorized)); + setError( + intl.formatMessage(messages.errorUnauthorized, { + mediaServerName, + }) + ); } else if (e instanceof RequestError && e.status == 422) { - setError(intl.formatMessage(messages.errorExists)); + setError( + intl.formatMessage(messages.errorExists, { applicationName }) + ); } else { - setError(intl.formatMessage(messages.errorServer)); + setError(intl.formatMessage(messages.errorUnknown)); } } }} @@ -116,12 +130,13 @@ const LinkJellyfinModal: React.FC = ({ } okDisabled={isSubmitting || !isValid} onOk={() => handleSubmit()} - title={intl.formatMessage(messages.title)} + title={intl.formatMessage(messages.title, { mediaServerName })} dialogClass="sm:max-w-lg" >