From bb42281dacf5f80be6c500634433a37c3db9447b Mon Sep 17 00:00:00 2001 From: kikootwo Date: Tue, 23 Dec 2025 13:38:13 -0500 Subject: [PATCH] Improve user auth handling and download monitoring Adds detection of local users for authentication validation and login, prevents role changes for OIDC users, and clarifies user management UI. Enhances active downloads API to include speed and ETA from qBittorrent, and improves file path handling in download monitoring. Also updates torrent tagging and user info returned by APIs. --- src/app/admin/settings/page.tsx | 42 +++++++--- src/app/admin/users/page.tsx | 19 ++++- src/app/api/admin/downloads/active/route.ts | 81 +++++++++++++++---- src/app/api/admin/settings/route.ts | 6 ++ src/app/api/admin/users/[id]/route.ts | 11 ++- src/app/api/admin/users/route.ts | 1 + src/app/api/auth/providers/route.ts | 20 ++++- src/app/login/page.tsx | 2 + src/lib/integrations/qbittorrent.service.ts | 1 + .../processors/download-torrent.processor.ts | 6 +- .../processors/monitor-download.processor.ts | 20 +++-- 11 files changed, 169 insertions(+), 40 deletions(-) diff --git a/src/app/admin/settings/page.tsx b/src/app/admin/settings/page.tsx index 5dc076d..a7bbdc8 100644 --- a/src/app/admin/settings/page.tsx +++ b/src/app/admin/settings/page.tsx @@ -31,6 +31,7 @@ interface IndexerConfig { interface Settings { backendMode: 'plex' | 'audiobookshelf'; + hasLocalUsers: boolean; plex: { url: string; token: string; @@ -777,12 +778,12 @@ export default function AdminSettings() { break; case 'auth': - // Validate: In Audiobookshelf mode, at least one auth method must be enabled + // Validate: In Audiobookshelf mode, at least one auth method must be enabled OR local users must exist if (settings.backendMode === 'audiobookshelf') { - if (!settings.oidc.enabled && !settings.registration.enabled) { + if (!settings.oidc.enabled && !settings.registration.enabled && !settings.hasLocalUsers) { setMessage({ type: 'error', - text: 'At least one authentication method must be enabled (OIDC or Manual Registration). Otherwise, users will not be able to log in.', + text: 'At least one authentication method must be enabled (OIDC or Manual Registration) since no local users exist. Otherwise, you will be locked out of the system.', }); setSaving(false); return; @@ -2296,8 +2297,8 @@ export default function AdminSettings() { - {/* Warning: No auth methods enabled */} - {settings.backendMode === 'audiobookshelf' && !settings.oidc.enabled && !settings.registration.enabled && ( + {/* Warning: No auth methods enabled AND no local users exist */} + {settings.backendMode === 'audiobookshelf' && !settings.oidc.enabled && !settings.registration.enabled && !settings.hasLocalUsers && (
@@ -2305,11 +2306,30 @@ export default function AdminSettings() {

- No Authentication Methods Enabled + No Authentication Methods Available

- You must enable at least one authentication method (OIDC or Manual Registration). - If you save with both disabled, users will not be able to log in to the system. + You must enable at least one authentication method (OIDC or Manual Registration) since no local users exist. + Saving with both disabled will lock you out of the system. +

+
+
+
+ )} + + {/* Info: Registration disabled but local users can still log in */} + {settings.backendMode === 'audiobookshelf' && !settings.oidc.enabled && !settings.registration.enabled && settings.hasLocalUsers && ( +
+
+ + + +
+

+ Manual Registration Disabled +

+

+ New user registration is disabled. Existing local users can still log in with their credentials.

@@ -2501,10 +2521,12 @@ export default function AdminSettings() { return !validated.audiobookshelf; } } - // For Auth tab: disable if no auth methods are enabled in Audiobookshelf mode + // For Auth tab: disable if no auth methods are enabled AND no local users exist in Audiobookshelf mode if (activeTab === 'auth' && settings) { if (settings.backendMode === 'audiobookshelf') { - return !settings.oidc.enabled && !settings.registration.enabled; + // Allow disabling both if local users exist (they can still log in) + // Prevent disabling both if no local users exist (would lock out system) + return !settings.oidc.enabled && !settings.registration.enabled && !settings.hasLocalUsers; } return false; } diff --git a/src/app/admin/users/page.tsx b/src/app/admin/users/page.tsx index f49bfa0..086672a 100644 --- a/src/app/admin/users/page.tsx +++ b/src/app/admin/users/page.tsx @@ -19,6 +19,7 @@ interface User { plexEmail: string; role: 'user' | 'admin'; isSetupAdmin: boolean; + authProvider: string | null; avatarUrl: string | null; createdAt: string; updatedAt: string; @@ -247,7 +248,7 @@ function AdminUsersPageContent() { )} {/* Users Table */} -
+
@@ -287,8 +288,11 @@ function AdminUsersPageContent() {
{user.plexUsername}
-
- Plex ID: {user.plexId} +
+ ID: {user.plexId.length > 12 ? `${user.plexId.substring(0, 12)}...` : user.plexId}
@@ -332,6 +336,13 @@ function AdminUsersPageContent() { Protected + ) : user.authProvider === 'oidc' ? ( + + + + + OIDC Managed + ) : (