Skip to content

Commit

Permalink
feat: check if first jellyfin user is admin
Browse files Browse the repository at this point in the history
Solves issue Fallenbagel#610 by checking if the first Jellyfin user (at initial set-up) is an admin on Jellyfin
or not, as required for set-up.

re Fallenbagel#610
  • Loading branch information
Danish-H committed Jan 26, 2024
1 parent 7af193b commit cf4015b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server/api/jellyfin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export interface JellyfinUserResponse {
ServerId: string;
ServerName: string;
Id: string;
Policy: {
IsAdministrator: boolean;
};
PrimaryImageTag?: string;
}

Expand Down
9 changes: 9 additions & 0 deletions server/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ authRoutes.post('/jellyfin', async (req, res, next) => {
// and give them admin permissions
const totalUsers = await userRepository.count();
if (totalUsers === 0) {
// Check if user is admin on jellyfin
if (account.User.Policy.IsAdministrator === false) {
throw new Error('not_admin');
}
logger.info(
'Sign-in attempt from Jellyfin user with access to the media server; creating initial admin user for Overseerr',
{
Expand Down Expand Up @@ -395,6 +399,11 @@ authRoutes.post('/jellyfin', async (req, res, next) => {
status: 401,
message: 'Unauthorized',
});
} else if (e.message === 'not_admin') {
return next({
status: 403,
message: 'CREDENTIAL_ERROR_NOT_ADMIN',
});
} else if (e.message === 'add_email') {
return next({
status: 406,
Expand Down
3 changes: 3 additions & 0 deletions src/components/Login/JellyfinLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const messages = defineMessages({
validationusernamerequired: 'Username required',
validationpasswordrequired: 'Password required',
loginerror: 'Something went wrong while trying to sign in.',
adminerror: 'You must use an admin account to sign in.',
credentialerror: 'The username or password is incorrect.',
signingin: 'Signing in…',
signin: 'Sign In',
Expand Down Expand Up @@ -94,6 +95,8 @@ const JellyfinLogin: React.FC<JellyfinLoginProps> = ({
intl.formatMessage(
e.message == 'Request failed with status code 401'
? messages.credentialerror
: e.message == 'Request failed with status code 403'
? messages.adminerror
: messages.loginerror
),
{
Expand Down

0 comments on commit cf4015b

Please sign in to comment.