feat: add Jellyfin profile authentication

This commit is contained in:
WonderAliceUwU committed 2026-09-06 21:59:07 +02:00
1 parent 2095730eee
commit 0d86c6e91c
8 files changed
+771 -157

No files matched your search

+4 -4
View File
@@ -2,8 +2,8 @@
React + TypeScript frontend with a built-in Node backend for:
- master-password login with `HttpOnly` session cookie
- encrypted storage of service settings
- Jellyfin-profile login with an `HttpOnly` session cookie
- master-password protected administration and server-side service settings
- Jellyfin, Sonarr, Radarr, qBittorrent and TMDb integration
- a single production process for Docker/TrueNAS
@@ -27,7 +27,7 @@ That file contains:
- master-password verifier
- encryption salt
- encrypted application settings
- server-managed encryption key and encrypted application settings
If you do not persist `/app/data`, you will lose:
@@ -139,6 +139,6 @@ That dataset is the piece that must survive updates and image replacements.
On first boot there is no default password.
You create the master password in the UI.
You create the master password in the UI. It protects the Administration area; viewers sign in from the profile screen using their own Jellyfin password.
After that, OmniArr stores only the verifier and encrypted settings in `/app/data/omniarr.secure.json`.
+118 -17
View File
@@ -8,12 +8,14 @@ import {
type EpisodeRequestPayload,
type EpisodeWatchStateRequest,
type DiskSpaceStatus,
type HubPageResponse,
type JellyfinLoginPayload,
type SeasonDeletePayload,
type SeasonRequestPayload,
type TitleDetailsRequest
} from '../shared/contracts.js';
import { decryptJson, deriveEncryptionKey, encryptJson, randomToken, verifyPassword, createPasswordRecord } from './lib/security.js';
import { loadState, readAdmin, readEncryptedConfig, saveAdminAndConfig, updateEncryptedConfig } from './lib/store.js';
import { loadState, migrateConfig, readAdmin, readEncryptedConfig, saveAdminAndConfig, updateEncryptedConfig } from './lib/store.js';
import {
getCalendar,
getConnectionStatuses,
@@ -26,6 +28,7 @@ import {
deleteSeasonFiles,
getServiceOptions,
loadJellyfinUsers,
authenticateJellyfinUser,
proxyJellyfinImage,
removeDownload,
requestEpisode,
@@ -40,7 +43,9 @@ import {
} from './lib/services.js';
interface SessionRecord {
encryptionKey: Buffer;
role: 'admin' | 'user';
userId?: string;
encryptionKey?: Buffer;
expiresAt: number;
}
@@ -48,6 +53,7 @@ const PORT = Number(process.env.PORT || 8787);
const SESSION_COOKIE = 'omniarr_session';
const SESSION_TTL_MS = 1000 * 60 * 60 * 12;
const sessions = new Map<string, SessionRecord>();
const sessionUsers = new WeakMap<Buffer, string>();
const failedAttempts = new Map<string, { count: number; lastAttempt: number }>();
const server = createServer(async (request, response) => {
@@ -84,7 +90,9 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse):
const session = getSession(request);
sendJson(response, 200, {
needsSetup: !state.admin,
authenticated: Boolean(session)
authenticated: Boolean(session),
role: session?.role,
userId: session?.userId
});
return;
}
@@ -106,16 +114,17 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse):
}
const record = createPasswordRecord(password);
const encryptionKey = deriveEncryptionKey(password, record.encryptionSalt);
const configKey = createConfigKey();
await saveAdminAndConfig(
{
...record,
createdAt: new Date().toISOString()
},
encryptJson(defaultConfig, encryptionKey)
encryptJson(defaultConfig, Buffer.from(configKey)),
configKey
);
const token = createSession(encryptionKey);
const token = createSession({ role: 'admin', encryptionKey: Buffer.from(randomToken()) });
setSessionCookie(request, response, token);
resetFailedAttempts(getClientAddress(request));
console.log('Register completed successfully');
@@ -149,8 +158,14 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse):
return;
}
const encryptionKey = deriveEncryptionKey(password, admin.encryptionSalt);
const token = createSession(encryptionKey);
const legacyEncryptionKey = deriveEncryptionKey(password, admin.encryptionSalt);
const state = await loadState();
if (!state.configKey && state.config) {
const config = await readConfig(legacyEncryptionKey);
const configKey = createConfigKey();
await migrateConfig(encryptJson(config, Buffer.from(configKey)), configKey);
}
const token = createSession({ role: 'admin', encryptionKey: Buffer.from(randomToken()) });
setSessionCookie(request, response, token);
resetFailedAttempts(getClientAddress(request));
console.log('Login completed successfully');
@@ -161,6 +176,53 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse):
return;
}
if (url.pathname === '/api/auth/profiles' && method === 'GET') {
try {
const config = await readConfig();
const [jellyfinUsers, connections] = await Promise.all([
loadJellyfinUsers(config.jellyfin.baseUrl, config.jellyfin.apiKey),
getConnectionStatuses(config)
]);
sendJson(response, 200, { jellyfinUsers, connections });
} catch {
sendJson(response, 409, { error: 'An administrator must sign in once to migrate the existing configuration.' });
}
return;
}
if (url.pathname.startsWith('/api/auth/profile-image/') && method === 'GET') {
const config = await readConfig();
const userId = decodeURIComponent(url.pathname.replace('/api/auth/profile-image/', ''));
const image = await proxyJellyfinImage(config, userId, 'Primary', 160, url.searchParams.get('tag') || '', true);
if (!image) {
sendJson(response, 404, { error: 'Profile image not found.' });
return;
}
response.writeHead(200, { 'Content-Type': image.contentType || 'image/jpeg', 'Cache-Control': 'private, max-age=3600' });
response.end(Buffer.from(image.data));
return;
}
if (url.pathname === '/api/auth/profile-login' && method === 'POST') {
if (isRateLimited(getClientAddress(request))) {
sendJson(response, 429, { error: 'Too many attempts. Wait one minute.' });
return;
}
const body = await readJson<JellyfinLoginPayload>(request);
const config = await readConfig();
const userId = String(body.userId || '');
if (!await authenticateJellyfinUser(config, userId, String(body.password || ''))) {
trackFailedAttempt(getClientAddress(request));
sendJson(response, 401, { error: 'Incorrect Jellyfin password.' });
return;
}
const token = createSession({ role: 'user', userId, encryptionKey: Buffer.from(randomToken()) });
setSessionCookie(request, response, token);
resetFailedAttempts(getClientAddress(request));
sendJson(response, 200, { ok: true, needsSetup: false });
return;
}
if (url.pathname === '/api/auth/logout' && method === 'POST') {
const token = getSessionToken(request);
if (token) {
@@ -178,16 +240,21 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse):
return;
}
if (url.pathname === '/api/settings' && method === 'PUT' && session?.role !== 'admin') {
sendJson(response, 403, { error: 'Administrator access is required.' });
return;
}
if (url.pathname === '/api/settings' && method === 'GET') {
const config = await readConfig(session!.encryptionKey);
sendJson(response, 200, config);
sendJson(response, 200, session!.role === 'admin' ? config : redactConfig(config));
return;
}
if (url.pathname === '/api/settings' && method === 'PUT') {
const body = await readJson<AppConfig>(request);
const config = sanitizeConfig(body);
await updateEncryptedConfig(encryptJson(config, session!.encryptionKey));
await updateEncryptedConfig(encryptJson(config, await getConfigEncryptionKey()));
const connections = await getConnectionStatuses(config);
sendJson(response, 200, {
config,
@@ -227,7 +294,7 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse):
const page = decodeURIComponent(url.pathname.replace('/api/hubs/', ''));
console.log(`[API] GET /api/hubs/${page}`);
try {
const result = await getHubPage(config, page as any);
const result = await getHubPage(config, page as HubPageResponse['page']);
sendJson(response, 200, result);
} catch (err) {
console.error(`[API] Error in GET /api/hubs/${page}:`, err);
@@ -259,7 +326,7 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse):
if (startParam) {
try {
start = new Date(startParam);
} catch (e) {
} catch {
// ignore invalid date
}
}
@@ -267,7 +334,7 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse):
if (endParam) {
try {
end = new Date(endParam);
} catch (e) {
} catch {
// ignore invalid date
}
}
@@ -401,15 +468,22 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse):
await serveApp(url.pathname, response);
}
function createSession(encryptionKey: Buffer): string {
function createSession(session: Omit<SessionRecord, 'expiresAt'>): string {
const token = randomToken();
if (session.userId && session.encryptionKey) {
sessionUsers.set(session.encryptionKey, session.userId);
}
sessions.set(token, {
encryptionKey,
...session,
expiresAt: Date.now() + SESSION_TTL_MS
});
return token;
}
function createConfigKey(): string {
return randomToken().slice(0, 32);
}
async function getDiskSpaceStatus(config: AppConfig): Promise<DiskSpaceStatus | null> {
return getMediaDiskSpace(config);
}
@@ -466,15 +540,21 @@ function clearSessionCookie(request: IncomingMessage, response: ServerResponse):
);
}
async function readConfig(encryptionKey: Buffer): Promise<AppConfig> {
async function readConfig(legacyEncryptionKey?: Buffer): Promise<AppConfig> {
const encrypted = await readEncryptedConfig();
if (!encrypted) {
return defaultConfig;
}
const state = await loadState();
const encryptionKey = state.configKey ? Buffer.from(state.configKey) : legacyEncryptionKey;
if (!encryptionKey) {
throw new Error('The configuration must be unlocked by an administrator.');
}
const stored = decryptJson<Partial<AppConfig>>(encrypted, encryptionKey);
return sanitizeConfig({
const config = sanitizeConfig({
preferences: {
...defaultConfig.preferences,
...(stored.preferences || {})
@@ -500,6 +580,27 @@ async function readConfig(encryptionKey: Buffer): Promise<AppConfig> {
...(stored.tvdb || {})
}
});
const userId = legacyEncryptionKey ? sessionUsers.get(legacyEncryptionKey) : undefined;
return userId ? { ...config, jellyfin: { ...config.jellyfin, userId } } : config;
}
async function getConfigEncryptionKey(): Promise<Buffer> {
const state = await loadState();
if (!state.configKey) {
throw new Error('The configuration must be unlocked by an administrator.');
}
return Buffer.from(state.configKey);
}
function redactConfig(config: AppConfig): AppConfig {
return {
...config,
jellyfin: { ...config.jellyfin, apiKey: 'configured' },
sonarr: { ...config.sonarr, apiKey: '' },
radarr: { ...config.radarr, apiKey: '' },
tmdb: { ...config.tmdb, bearerToken: '' },
tvdb: { ...config.tvdb, apiKey: '' }
};
}
async function readJson<T>(request: IncomingMessage): Promise<T> {
+40 -6
View File
@@ -517,6 +517,33 @@ export async function loadJellyfinUsers(baseUrl: string, apiKey: string): Promis
return getJellyfinUsersFromConfig(normalizeBaseUrl(baseUrl), apiKey.trim());
}
export async function authenticateJellyfinUser(config: AppConfig, userId: string, password: string): Promise<boolean> {
if (!config.jellyfin.baseUrl || !userId || !password) {
return false;
}
const authorization = 'MediaBrowser Client="OmniArr", Device="OmniArr", DeviceId="omniarr-web", Version="1.0.0"';
const response = await fetch(`${config.jellyfin.baseUrl}/Users/AuthenticateByName`, {
method: 'POST',
headers: {
Authorization: authorization,
'X-Emby-Authorization': authorization,
'Content-Type': 'application/json'
},
body: JSON.stringify({
Username: (await getJellyfinUsers(config)).find((user) => user.id === userId)?.label || '',
Pw: password
})
});
if (!response.ok) {
return false;
}
const payload = await response.json() as { User?: { Id?: string } };
return payload.User?.Id === userId;
}
export async function getDashboard(config: AppConfig): Promise<DashboardResponse> {
const [connections, library, downloads, tmdb] = await Promise.all([
getConnectionStatuses(config),
@@ -2743,12 +2770,14 @@ export async function proxyJellyfinImage(
itemId: string,
kind: string,
maxWidth: number,
tag: string
tag: string,
isUser = false
): Promise<{ data: ArrayBuffer; contentType: string | null } | null> {
const candidates = kind === 'Primary' ? ['Primary'] : [kind, 'Primary'];
for (const candidate of candidates) {
const path = `/Items/${encodeURIComponent(itemId)}/Images/${encodeURIComponent(candidate)}?quality=90&maxWidth=${maxWidth}&tag=${encodeURIComponent(tag)}`;
const collection = isUser ? 'Users' : 'Items';
const path = `/${collection}/${encodeURIComponent(itemId)}/Images/${encodeURIComponent(candidate)}?quality=90&maxWidth=${maxWidth}&tag=${encodeURIComponent(tag)}`;
const response = await fetch(`${config.jellyfin.baseUrl}${path}`, {
headers: {
'X-Emby-Token': config.jellyfin.apiKey
@@ -3361,10 +3390,15 @@ async function getJellyfinUsersFromConfig(baseUrl: string, apiKey: string): Prom
}
);
return users.map((user) => ({
id: String(user.Id || ''),
label: String(user.Name || user.Id || 'User')
}));
return users.map((user) => {
const id = String(user.Id || '');
const imageTag = String(user.PrimaryImageTag || '');
return {
id,
label: String(user.Name || user.Id || 'User'),
...(imageTag ? { imageUrl: `/api/auth/profile-image/${encodeURIComponent(id)}?tag=${encodeURIComponent(imageTag)}` } : {})
};
});
}
async function getSonarrRootFolders(config: AppConfig): Promise<SelectOption[]> {
+17 -12
View File
@@ -13,9 +13,10 @@ interface EncryptedConfig {
}
interface StoredState {
version: 1;
version: 1 | 2;
admin: StoredAdmin | null;
config: EncryptedConfig | null;
configKey: string | null;
}
const DATA_DIR = resolve(process.env.OMNIARR_DATA_DIR || resolve(process.cwd(), 'data'));
@@ -24,7 +25,8 @@ const STORE_FILE = resolve(DATA_DIR, 'omniarr.secure.json');
const EMPTY_STATE: StoredState = {
version: 1,
admin: null,
config: null
config: null,
configKey: null
};
export async function loadState(): Promise<StoredState> {
@@ -33,9 +35,10 @@ export async function loadState(): Promise<StoredState> {
const parsed = JSON.parse(raw) as Partial<StoredState>;
return {
version: 1,
version: parsed.configKey ? 2 : 1,
admin: parsed.admin ?? null,
config: parsed.config ?? null
config: parsed.config ?? null,
configKey: typeof parsed.configKey === 'string' ? parsed.configKey : null
};
} catch {
return EMPTY_STATE;
@@ -47,11 +50,6 @@ export async function saveState(state: StoredState): Promise<void> {
await writeFile(STORE_FILE, JSON.stringify(state, null, 2), 'utf8');
}
export async function needsSetup(): Promise<boolean> {
const state = await loadState();
return !state.admin;
}
export async function readEncryptedConfig(): Promise<EncryptedConfig | null> {
const state = await loadState();
return state.config;
@@ -59,12 +57,14 @@ export async function readEncryptedConfig(): Promise<EncryptedConfig | null> {
export async function saveAdminAndConfig(
admin: StoredAdmin,
config: EncryptedConfig
config: EncryptedConfig,
configKey: string
): Promise<void> {
await saveState({
version: 1,
version: 2,
admin,
config
config,
configKey
});
}
@@ -81,4 +81,9 @@ export async function readAdmin(): Promise<StoredAdmin | null> {
return state.admin;
}
export async function migrateConfig(config: EncryptedConfig, configKey: string): Promise<void> {
const state = await loadState();
await saveState({ ...state, version: 2, config, configKey });
}
export type { EncryptedConfig, StoredAdmin, StoredState };
+7
View File
@@ -67,6 +67,7 @@ export interface AppConfig {
export interface SelectOption {
id: string;
label: string;
imageUrl?: string;
}
export interface ServiceOptionsResponse {
@@ -313,12 +314,18 @@ export interface HubPageResponse {
export interface SessionResponse {
needsSetup: boolean;
authenticated: boolean;
role?: 'admin' | 'user';
userId?: string;
}
export interface AuthPayload {
password: string;
}
export interface JellyfinLoginPayload extends AuthPayload {
userId: string;
}
export interface AuthResponse {
ok: boolean;
needsSetup: boolean;
+265 -76
View File
@@ -31,7 +31,7 @@ import {
type TitleDetailsResponse,
} from '../shared/contracts'
type AuthState = 'loading' | 'setup' | 'login' | 'app'
type AuthState = 'loading' | 'setup' | 'login' | 'profiles' | 'admin' | 'app'
type EntryStage = 'onboarding' | 'profiles' | 'dashboard'
type EntryTransitionState = 'idle' | 'forward-enter' | 'forward-exit' | 'back-enter' | 'back-exit'
const MAX_CACHED_HUB_PAGES = 3
@@ -67,6 +67,7 @@ const networkSidebarItems: Array<{ route: AppRoute; label: string; icon: string;
function App() {
const [authState, setAuthState] = useState<AuthState>('loading')
const [sessionRole, setSessionRole] = useState<'admin' | 'user' | null>(null)
const [entryStage, setEntryStage] = useState<EntryStage>('profiles')
const [route, setRoute] = useState<AppRoute>('home')
const [busy, setBusy] = useState(false)
@@ -171,18 +172,21 @@ function App() {
}
if (!session.authenticated) {
setAuthState('login')
const profiles = await api.getProfiles()
if (cancelled) return
setOptions((current) => ({ ...current, jellyfinUsers: profiles.jellyfinUsers }))
setConnections(profiles.connections)
setAuthState('profiles')
return
}
setSessionRole(session.role ?? null)
await refreshBaseData()
if (!cancelled) {
setAuthState('app')
}
if (!cancelled) setAuthState(session.role === 'admin' ? 'admin' : 'app')
} catch (bootError) {
if (!cancelled) {
setError(bootError instanceof Error ? bootError.message : 'Failed to start OmniArr.')
setAuthState('login')
setAuthState('profiles')
}
}
}
@@ -258,10 +262,13 @@ function App() {
}
await refreshBaseData()
setPassword('')
setSessionRole('admin')
if (authState === 'setup') {
setNotice('Instance initialized.')
} else {
setRoute('settings')
}
setAuthState('app')
setAuthState(authState === 'setup' ? 'app' : 'admin')
} catch (authError) {
setError(authError instanceof Error ? authError.message : 'Authentication failed.')
} finally {
@@ -288,23 +295,17 @@ function App() {
}
}
async function handleSelectJellyfinUser(userId: string) {
async function handleSelectJellyfinUser(userId: string, jellyfinPassword: string) {
setBusy(true)
setError('')
setNotice('')
try {
const nextConfig = {
...config,
jellyfin: {
...config.jellyfin,
userId,
},
}
const response = await api.saveSettings(nextConfig)
setConfig(response.config)
await api.loginProfile({ userId, password: jellyfinPassword })
setSessionRole('user')
await refreshBaseData()
await transitionEntryStage('dashboard')
setRoute('home')
setAuthState('app')
} catch (selectError) {
setError(selectError instanceof Error ? selectError.message : 'Failed to select Jellyfin profile.')
} finally {
@@ -422,12 +423,11 @@ function App() {
return <LoadingScreen />
}
if (authState === 'setup' || authState === 'login') {
if (authState === 'setup') {
return (
<AuthScreen
busy={busy}
error={error}
mode={authState}
onSubmit={handleAuthSubmit}
password={password}
setPassword={setPassword}
@@ -435,6 +435,50 @@ function App() {
)
}
if (authState === 'login') {
return (
<AdministrationLoginScreen
busy={busy}
error={error}
onBack={() => { setPassword(''); setAuthState('profiles') }}
onSubmit={handleAuthSubmit}
password={password}
setPassword={setPassword}
/>
)
}
if (authState === 'profiles') {
return (
<ProfileSelectionScreen
busy={busy}
currentUserId=""
hasServiceFailure={connections.some((connection) => !connection.ok)}
error={error}
notice={notice}
onAdmin={() => setAuthState(sessionRole === 'admin' ? 'admin' : 'login')}
onSelectUser={handleSelectJellyfinUser}
users={options.jellyfinUsers}
/>
)
}
if (authState === 'admin') {
return (
<AdministrationScreen
busy={busy}
config={config}
connections={connections}
jellyfinUsersBusy={jellyfinUsersBusy}
onExit={() => setAuthState('profiles')}
onLoadJellyfinUsers={handleLoadJellyfinUsers}
onSave={handleSaveSettings}
options={options}
updateConfig={updateConfig}
/>
)
}
if (entryStage === 'onboarding') {
return (
<JellyfinOnboardingScreen
@@ -460,10 +504,12 @@ function App() {
<div className={getEntryTransitionClassName(entryTransitionState)}>
<ProfileSelectionScreen
busy={busy}
currentUserId={config.jellyfin.userId}
currentUserId={sessionRole === 'user' ? config.jellyfin.userId : ''}
hasServiceFailure={connections.some((connection) => !connection.ok)}
error={error}
notice={notice}
onBackToOnboarding={() => void transitionEntryStage('onboarding')}
onAdmin={() => setAuthState(sessionRole === 'admin' ? 'admin' : 'login')}
onContinue={() => void transitionEntryStage('dashboard')}
onSelectUser={handleSelectJellyfinUser}
users={options.jellyfinUsers}
/>
@@ -471,8 +517,9 @@ function App() {
)
}
const currentJellyfinUser =
options.jellyfinUsers.find((option) => option.id === config.jellyfin.userId)?.label || 'Media cockpit'
const currentJellyfinUser = sessionRole === 'admin'
? 'Administration'
: options.jellyfinUsers.find((option) => option.id === config.jellyfin.userId)?.label || 'Media cockpit'
const currentHub = route !== 'downloads' && route !== 'settings' && route !== 'calendar' && route !== 'search' ? hubPages[route as HubPageResponse['page']] : undefined
return (
@@ -483,6 +530,7 @@ function App() {
currentUser={currentJellyfinUser}
diskSpace={diskSpace}
onExitProfile={() => void transitionEntryStage('profiles')}
canManage={sessionRole === 'admin'}
route={route}
setRoute={setRoute}
/>
@@ -564,6 +612,7 @@ function Sidebar(props: {
diskSpace: DiskSpaceStatus | null
connections: ConnectionStatus[]
busy: boolean
canManage: boolean
onExitProfile: () => void
}) {
const [menuOpen, setMenuOpen] = useState(false)
@@ -673,7 +722,7 @@ function Sidebar(props: {
<div className="sidebar-footer">
{props.diskSpace ? <DiskSpaceIndicator diskSpace={props.diskSpace} /> : null}
<button className="ghost-button sidebar-settings" onClick={() => navigate('settings')} type="button">
{props.canManage ? <button className="ghost-button sidebar-settings" onClick={() => navigate('settings')} type="button">
<span className="sidebar-settings-icon" aria-hidden="true">
<SettingsGlyph />
<span
@@ -683,6 +732,7 @@ function Sidebar(props: {
</span>
<span>Settings</span>
</button>
: null}
</div>
</div>
</aside>
@@ -817,14 +867,12 @@ function ActionButton(props: {
}
function AuthScreen({
mode,
password,
setPassword,
onSubmit,
busy,
error,
}: {
mode: 'setup' | 'login'
password: string
setPassword: (value: string) => void
onSubmit: () => Promise<void>
@@ -832,7 +880,6 @@ function AuthScreen({
error: string
}) {
const isPasswordValid = password.trim().length >= 8
const isSetup = mode === 'setup'
function handleSubmit() {
if (busy || !isPasswordValid) {
@@ -843,15 +890,11 @@ function AuthScreen({
}
return (
<div className={isSetup ? 'auth-layout' : 'auth-layout auth-layout-login'}>
<section className={isSetup ? 'auth-panel' : 'auth-panel auth-panel-login'}>
<div className="auth-layout">
<section className="auth-panel">
<div className="auth-panel-shell">
<h1>{isSetup ? 'Create your master password' : 'Sign in to OmniArr'}</h1>
<p className="auth-copy">
{isSetup
? 'This password protects the session and encrypts service settings on the server.'
: 'Unlock the server session with your master password.'}
</p>
<h1>Create your master password</h1>
<p className="auth-copy">This password protects the administration area and service settings.</p>
</div>
<div className="auth-form-card">
<form
@@ -862,45 +905,39 @@ function AuthScreen({
}}
>
<label>
{isSetup ? 'Master password' : 'Password'}
Master password
<input
autoComplete={isSetup ? 'new-password' : 'current-password'}
autoComplete="new-password"
className="input"
minLength={8}
onChange={(event) => setPassword(event.target.value)}
placeholder={isSetup ? 'At least 8 characters' : ''}
placeholder="At least 8 characters"
type="password"
value={password}
/>
</label>
{isSetup && !isPasswordValid && password.length > 0 ? <p className="helper-text">Password must be at least 8 non-space characters.</p> : null}
{!isPasswordValid && password.length > 0 ? <p className="helper-text">Password must be at least 8 non-space characters.</p> : null}
{error ? <p className="error-banner">{error}</p> : null}
{busy ? <p className="notice">Contacting backend…</p> : null}
<button className="primary-button" disabled={busy || !isPasswordValid} type="submit">
{busy ? 'Processing…' : isSetup ? 'Initialize' : 'Sign in'}
{busy ? 'Processing…' : 'Initialize'}
</button>
</form>
</div>
</section>
{isSetup ? (
<section className="auth-visual">
<div className="auth-wallpaper" />
<div className="glass-card">
<p className="eyebrow">Migration</p>
<ul className="feature-list">
<li>Server-side session auth</li>
<li>Encrypted persisted settings</li>
<li>Jellyfin, Sonarr and Radarr</li>
<li>Rebuilt React UI with shared layout</li>
</ul>
</div>
</section>
) : (
<section className="auth-visual auth-visual-login" aria-hidden="true">
<div className="auth-wallpaper" />
</section>
)}
<section className="auth-visual">
<div className="auth-wallpaper" />
<div className="glass-card">
<p className="eyebrow">Migration</p>
<ul className="feature-list">
<li>Server-side session auth</li>
<li>Encrypted persisted settings</li>
<li>Jellyfin, Sonarr and Radarr</li>
<li>Rebuilt React UI with shared layout</li>
</ul>
</div>
</section>
</div>
)
}
@@ -947,7 +984,7 @@ function JellyfinOnboardingScreen(props: {
<div className="profile-grid compact">
{props.users.map((user) => (
<div className="profile-card static" key={user.id}>
<div className="profile-avatar">{user.label.slice(0, 1).toUpperCase()}</div>
<ProfileAvatar user={user} />
<strong>{user.label}</strong>
</div>
))}
@@ -961,43 +998,152 @@ function JellyfinOnboardingScreen(props: {
function ProfileSelectionScreen(props: {
users: SelectOption[]
currentUserId: string
hasServiceFailure: boolean
busy: boolean
error: string
notice: string
onSelectUser: (userId: string) => Promise<void>
onBackToOnboarding: () => void
onSelectUser: (userId: string, password: string) => Promise<void>
onAdmin: () => void
onContinue?: () => void
}) {
const [selectedUserId, setSelectedUserId] = useState('')
const [password, setPassword] = useState('')
const [isReturning, setIsReturning] = useState(false)
const [hasReturned, setHasReturned] = useState(false)
const [isSelecting, setIsSelecting] = useState(false)
const [isEntering, setIsEntering] = useState(false)
function submit() {
if (selectedUserId && password) {
void props.onSelectUser(selectedUserId, password)
}
}
function goBack() {
setIsReturning(true)
window.setTimeout(() => {
setSelectedUserId('')
setPassword('')
setIsReturning(false)
setHasReturned(true)
window.setTimeout(() => setHasReturned(false), 520)
}, 240)
}
function selectProfile(userId: string) {
setIsSelecting(true)
window.setTimeout(() => {
setSelectedUserId(userId)
setIsSelecting(false)
setIsEntering(true)
window.setTimeout(() => setIsEntering(false), 520)
}, 240)
}
const selectedUser = props.users.find((user) => user.id === selectedUserId)
return (
<div className="profiles-layout">
<div className={selectedUser ? `profiles-layout is-profile-login${isReturning ? ' is-returning' : ''}${isEntering ? ' is-entering' : ''}` : `profiles-layout${hasReturned ? ' is-profile-return' : ''}${isSelecting ? ' is-profile-selecting' : ''}`}>
<div className="profiles-header">
<p className="eyebrow">Profiles</p>
<h1>Who&apos;s watching?</h1>
<h1>{selectedUser ? `Sign in as ${selectedUser.label}` : 'Who\'s watching?'}</h1>
{props.error ? <p className="error-banner">{props.error}</p> : null}
{props.notice ? <p className="notice">{props.notice}</p> : null}
</div>
<div className="profile-grid">
{selectedUser ? <ProfileLoginForm busy={props.busy} icon={<ProfileAvatar user={selectedUser} />} onBack={goBack} onSubmit={submit} password={password} placeholder="Enter the password" setPassword={setPassword} /> : <div className="profile-grid">
{props.users.map((user) => (
<button
className={user.id === props.currentUserId ? 'profile-card active' : 'profile-card'}
disabled={props.busy}
disabled={props.busy || isSelecting}
key={user.id}
onClick={() => void props.onSelectUser(user.id)}
onClick={() => {
if (user.id === props.currentUserId) {
props.onContinue?.()
} else {
selectProfile(user.id)
}
}}
type="button"
>
<div className="profile-avatar">{user.label.slice(0, 1).toUpperCase()}</div>
<ProfileAvatar user={user} />
<strong>{user.label}</strong>
{user.id === props.currentUserId ? <span className="profile-active-check" aria-label="Current profile">✓</span> : null}
</button>
))}
</div>
<div className="profiles-actions">
<button className="ghost-button" onClick={props.onBackToOnboarding} type="button">
Edit Jellyfin connection
</div>}
{!selectedUser ? <div className="profiles-actions">
<button aria-label="Administration" className="profile-admin-button" onClick={props.onAdmin} title="Administration" type="button">
<span className="profile-admin-icon">
<SettingsGlyph />
<span className={props.hasServiceFailure ? 'profile-admin-status down' : 'profile-admin-status ok'} />
</span>
</button>
</div>
</div> : null}
</div>
)
}
function ProfileAvatar({ user }: { user: SelectOption }) {
return <div className="profile-avatar">{user.imageUrl ? <img alt="" src={user.imageUrl} /> : user.label.slice(0, 1).toUpperCase()}</div>
}
function AdministrationLoginScreen(props: {
busy: boolean
error: string
password: string
setPassword: (value: string) => void
onBack: () => void
onSubmit: () => Promise<void>
}) {
const [isReturning, setIsReturning] = useState(false)
function goBack() {
setIsReturning(true)
window.setTimeout(props.onBack, 240)
}
return (
<div className={`profiles-layout is-profile-login is-entering${isReturning ? ' is-returning' : ''}`}>
<div className="profiles-header">
<h1>Administration</h1>
{props.error ? <p className="error-banner">{props.error}</p> : null}
</div>
<ProfileLoginForm busy={props.busy} icon={<div className="administration-login-icon"><SettingsGlyph /></div>} onBack={goBack} onSubmit={() => { void props.onSubmit() }} password={props.password} placeholder="Enter the master password" setPassword={props.setPassword} />
</div>
)
}
function ProfileLoginForm(props: {
busy: boolean
icon: ReactNode
password: string
placeholder: string
setPassword: (value: string) => void
onBack: () => void
onSubmit: () => void
}) {
return (
<form className="profile-login-form" onSubmit={(event) => { event.preventDefault(); props.onSubmit() }}>
{props.icon}
<label>
<input autoComplete="current-password" autoFocus className="input" onChange={(event) => props.setPassword(event.target.value)} placeholder={props.placeholder} type="password" value={props.password} />
</label>
<div className="profile-login-actions">
<button aria-label="Back to profiles" className="profile-login-back" onClick={props.onBack} title="Back to profiles" type="button"><ArrowLeftGlyph /></button>
<button aria-label="Sign in" className="profile-login-submit" disabled={props.busy || !props.password} title="Sign in" type="submit"><SignInGlyph /></button>
</div>
</form>
)
}
function SignInGlyph() {
return (
<svg aria-hidden="true" className="sidebar-glyph-icon" fill="none" viewBox="0 0 16 16">
<path d="M9.7 2.5H4.3A1.3 1.3 0 0 0 3 3.8v8.4a1.3 1.3 0 0 0 1.3 1.3h5.4" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.4" />
<path d="M8 8h5M10.85 5.15 13.7 8l-2.85 2.85" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.4" />
</svg>
)
}
function HubPageView(props: {
route: AppRoute
hub?: HubPageResponse
@@ -3159,6 +3305,47 @@ function formatCalendarTime(startsAt: string) {
}).format(date)
}
function AdministrationScreen(props: {
config: AppConfig
connections: ConnectionStatus[]
jellyfinUsersBusy: boolean
onExit: () => void
onLoadJellyfinUsers: () => Promise<void>
updateConfig: <K extends keyof AppConfig>(key: K, value: AppConfig[K]) => void
options: ServiceOptionsResponse
onSave: (event: FormEvent<HTMLFormElement>) => Promise<void>
busy: boolean
}) {
return (
<div className="administration-layout">
<header className="administration-header">
<button aria-label="Back to profiles" className="administration-back-button" onClick={props.onExit} title="Back to profiles" type="button">
<ArrowLeftGlyph />
</button>
<div>
<p className="eyebrow">Administration</p>
<h1>Settings</h1>
</div>
<button aria-label="Save settings" className={props.busy ? 'administration-save-button is-saving' : 'administration-save-button'} disabled={props.busy} form="administration-settings" title="Save settings" type="submit">
<CheckGlyph />
</button>
</header>
<SettingsView
busy={props.busy}
config={props.config}
connections={props.connections}
jellyfinUsersBusy={props.jellyfinUsersBusy}
onLoadJellyfinUsers={props.onLoadJellyfinUsers}
onSave={props.onSave}
options={props.options}
formId="administration-settings"
showSubmit={false}
updateConfig={props.updateConfig}
/>
</div>
)
}
function SettingsView(props: {
config: AppConfig
connections: ConnectionStatus[]
@@ -3168,9 +3355,11 @@ function SettingsView(props: {
options: ServiceOptionsResponse
onSave: (event: FormEvent<HTMLFormElement>) => Promise<void>
busy: boolean
formId?: string
showSubmit?: boolean
}) {
return (
<form className="settings-page" onSubmit={(event) => void props.onSave(event)}>
<form className="settings-page" id={props.formId} onSubmit={(event) => void props.onSave(event)}>
<SettingsCard title="Connections">
<div className="settings-connections">
{props.connections.map((connection) => (
@@ -3249,11 +3438,11 @@ function SettingsView(props: {
</label>
</SettingsCard>
<div className="actions-row">
{props.showSubmit !== false ? <div className="actions-row">
<button className="primary-button" disabled={props.busy} type="submit">
{props.busy ? 'Saving…' : 'Save settings'}
</button>
</div>
</div> : null}
</form>
)
}
+8
View File
@@ -3,10 +3,12 @@ import type {
AuthPayload,
AuthResponse,
CalendarResponse,
ConnectionStatus,
DashboardResponse,
DiskSpaceStatus,
DownloadsResponse,
HubPageResponse,
JellyfinLoginPayload,
MediaCard,
SearchResponse,
ServiceOptionsResponse,
@@ -67,6 +69,12 @@ export const api = {
method: 'POST',
body: JSON.stringify(payload),
}),
getProfiles: () => request<{ jellyfinUsers: ServiceOptionsResponse['jellyfinUsers']; connections: ConnectionStatus[] }>('/api/auth/profiles'),
loginProfile: (payload: JellyfinLoginPayload) =>
request<AuthResponse>('/api/auth/profile-login', {
method: 'POST',
body: JSON.stringify(payload),
}),
logout: () =>
request<AuthResponse>('/api/auth/logout', {
method: 'POST',
+312 -42
View File
@@ -20,7 +20,7 @@ body,
#root {
height: 100%;
margin: 0;
overflow: hidden;
overflow: visible;
}
body {
@@ -1878,7 +1878,7 @@ img {
display: grid;
grid-template-columns: minmax(0, 52rem) auto;
align-items: end;
gap: 1.25rem;
gap: 1rem;
}
.title-details-summary-copy {
@@ -3155,7 +3155,7 @@ img {
.download-row {
display: grid;
grid-template-columns: minmax(0, 1.3fr) minmax(18rem, 0.7fr);
gap: 1.25rem;
gap: 2rem;
padding: 1.1rem;
border-radius: 1.35rem;
background: rgba(255, 255, 255, 0.045);
@@ -3454,14 +3454,6 @@ img {
linear-gradient(180deg, #05070b, #090c12 42%, #06080d 100%);
}
.auth-layout-login {
position: relative;
grid-template-columns: minmax(0, 34rem);
justify-content: center;
align-content: center;
padding: 2rem;
}
.auth-panel,
.auth-visual {
padding: 3rem;
@@ -3473,13 +3465,6 @@ img {
gap: 1.25rem;
}
.auth-panel-login {
position: relative;
z-index: 1;
min-height: auto;
padding: 0;
}
.auth-panel-shell {
display: grid;
gap: 1rem;
@@ -3522,15 +3507,6 @@ img {
url('/omniarr/server-wallpaper.png') center/cover no-repeat;
}
.auth-visual-login {
position: fixed;
inset: 0;
z-index: 0;
padding: 0;
opacity: 0.6;
mask-image: linear-gradient(90deg, transparent 0%, rgba(0, 0, 0, 0.88) 18%, #000 100%);
}
.glass-card {
position: relative;
z-index: 1;
@@ -3576,7 +3552,8 @@ img {
}
.profiles-layout {
min-height: 100vh;
height: 100%;
overflow-y: auto;
display: grid;
align-content: center;
gap: 2rem;
@@ -3595,31 +3572,253 @@ img {
font-family: var(--font-display);
}
.profiles-layout.is-profile-login.is-entering .profiles-header,
.profiles-layout.is-profile-login.is-entering .profile-login-form {
animation: entryStageForwardEnter 520ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.profiles-layout.is-profile-login.is-returning .profiles-header,
.profiles-layout.is-profile-login.is-returning .profile-login-form {
animation: entryStageBackExit 240ms cubic-bezier(0.32, 0.9, 0.42, 1) both;
}
.profiles-layout.is-profile-return .profiles-header,
.profiles-layout.is-profile-return .profile-grid,
.profiles-layout.is-profile-return .profiles-actions {
animation: entryStageBackEnter 520ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.profiles-layout.is-profile-selecting .profiles-header,
.profiles-layout.is-profile-selecting .profile-grid,
.profiles-layout.is-profile-selecting .profiles-actions {
animation: entryStageForwardExit 240ms cubic-bezier(0.32, 0.9, 0.42, 1) both;
}
.profile-login-back {
display: grid;
place-items: center;
width: 2.6rem;
height: 2.6rem;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
color: #f5f7fb;
}
.profile-login-actions {
display: flex;
justify-content: space-between;
width: 100%;
}
.profile-login-submit {
display: grid;
place-items: center;
width: 2.6rem;
height: 2.6rem;
border: 0;
border-radius: 999px;
background: #68d391;
color: #07120d;
box-shadow: 0 0.35rem 1.1rem rgba(104, 211, 145, 0.28);
}
.profile-login-submit:hover {
filter: brightness(1.08);
transform: translateX(0.1rem);
}
.profile-login-back:hover {
background: rgba(255, 255, 255, 0.16);
transform: translateX(-0.15rem);
}
.profile-login-form {
display: grid;
justify-items: center;
gap: 1.15rem;
width: min(25rem, 100%);
margin: 0 auto;
padding: 1.5rem;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 1.5rem;
background: rgba(8, 12, 18, 0.72);
}
.profile-login-form label {
display: grid;
gap: 0.55rem;
width: 100%;
color: #c9d5e6;
}
.administration-login-icon {
display: grid;
place-items: center;
width: 4.5rem;
height: 4.5rem;
border-radius: 999px;
background: rgba(255, 255, 255, 0.1);
color: #e8edf8;
}
.administration-login-icon .sidebar-glyph-icon {
width: 1.7rem;
height: 1.7rem;
}
.profiles-actions {
display: flex;
justify-content: center;
}
.profile-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(10rem, 12rem));
justify-content: center;
gap: 1.25rem;
.administration-layout {
height: 100%;
overflow-y: auto;
padding: clamp(1.5rem, 5vw, 4rem);
background: #080c12;
}
.profile-grid.compact {
grid-template-columns: repeat(auto-fit, minmax(8rem, 10rem));
.administration-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
max-width: 76rem;
margin: 0 auto 2rem;
}
.administration-header h1 {
margin: 0.25rem 0 0;
font-family: var(--font-display);
}
.administration-back-button {
display: grid;
place-items: center;
width: 2.9rem;
height: 2.9rem;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
color: #f5f7fb;
}
.administration-back-button:hover {
background: rgba(255, 255, 255, 0.18);
box-shadow: -3px 6px 13px rgba(0, 0, 0, 0.25);
}
.administration-save-button {
display: grid;
place-items: center;
width: 2.9rem;
height: 2.9rem;
border: 0;
border-radius: 999px;
background: #68d391;
color: #07120d;
box-shadow: 0 0.35rem 1.1rem rgba(104, 211, 145, 0.28);
transition: transform 180ms ease, box-shadow 180ms ease, filter 180ms ease;
}
.administration-save-button svg {
width: 1.35rem;
height: 1.35rem;
}
.administration-save-button:hover {
filter: brightness(1.08);
transform: scale(1.08);
box-shadow: 0 0.5rem 1.4rem rgba(104, 211, 145, 0.46);
}
.administration-save-button.is-saving {
animation: administration-save-pulse 700ms ease-in-out infinite alternate;
}
.administration-save-button.is-saving svg {
animation: administration-save-check 700ms ease-in-out infinite;
}
@keyframes administration-save-pulse {
from { box-shadow: 0 0 0 0 rgba(104, 211, 145, 0.48); }
to { box-shadow: 0 0 0 0.65rem rgba(104, 211, 145, 0); }
}
@keyframes administration-save-check {
0%, 100% { transform: scale(1); }
50% { transform: scale(0.72) rotate(-10deg); }
}
.profile-admin-button {
display: grid;
place-items: center;
width: 2.9rem;
height: 2.9rem;
border: 0;
background: transparent;
color: #f5f7fb;
cursor: pointer;
}
.profile-admin-icon {
position: relative;
display: grid;
place-items: center;
width: 2rem;
height: 2rem;
border-radius: 0.7rem;
background: rgba(255, 255, 255, 0.1);
color: #e8edf8;
}
.profile-admin-icon .sidebar-glyph-icon {
width: 1rem;
height: 1rem;
}
.profile-admin-status {
position: absolute;
inset: -0.2rem;
border: 0.12rem solid currentColor;
border-radius: 999px;
pointer-events: none;
}
.profile-admin-status.ok { color: #59df8a; }
.profile-admin-status.down { color: #ff5d73; }
.profile-admin-button:hover {
transform: scale(1.04);
}
.profile-admin-button:hover .profile-admin-status {
box-shadow: 0 0 0.65rem currentColor;
}
.profile-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(7.2rem, 1fr));
justify-content: center;
gap: 2rem;
width: min(100%, 72rem);
margin: 0 auto;
}
.profile-card {
position: relative;
display: grid;
gap: 0.85rem;
justify-items: center;
padding: 1.25rem;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 1.5rem;
background: rgba(8, 12, 18, 0.72);
padding: 0.75rem;
border: 0;
border-radius: 1rem;
background: transparent;
color: #eef4ff;
transition: color 220ms ease;
}
.profile-card.static {
@@ -3627,8 +3826,15 @@ img {
}
.profile-card.active {
border-color: rgba(255, 209, 102, 0.45);
box-shadow: 0 0 0 1px rgba(255, 209, 102, 0.24) inset;
box-shadow: none;
}
.profile-card:not(:disabled):hover .profile-avatar {
transform: scale(1.08);
}
.profile-card:not(:disabled):hover strong {
color: #ffffff;
}
.profile-avatar {
@@ -3636,11 +3842,75 @@ img {
place-items: center;
width: 4.5rem;
height: 4.5rem;
border-radius: 1.2rem;
border-radius: 999px;
background: linear-gradient(135deg, #68abff, #ffd166);
color: #0f1420;
font-size: 1.5rem;
font-weight: 800;
overflow: hidden;
transition: transform 220ms cubic-bezier(.2, .8, .2, 1);
}
.profile-avatar img {
width: 100%;
height: 100%;
object-fit: cover;
}
.profile-active-check {
position: absolute;
top: 0.65rem;
right: 0.65rem;
display: grid;
place-items: center;
width: 1.4rem;
height: 1.4rem;
border-radius: 999px;
background: #68d391;
color: #07120d;
font-weight: 900;
}
@media (max-width: 600px) {
.profiles-layout {
align-content: start;
gap: 1.5rem;
padding: 2rem 1.25rem;
}
.profiles-header h1 {
font-size: clamp(1.8rem, 9vw, 2.5rem);
}
.profile-grid {
grid-template-columns: repeat(auto-fit, minmax(5.8rem, 1fr));
gap: 1rem;
width: 100%;
}
.profile-card {
gap: 0.55rem;
padding: 0.35rem;
min-width: 0;
}
.profile-avatar {
width: clamp(4.1rem, 20vw, 5.5rem);
height: clamp(4.1rem, 20vw, 5.5rem);
font-size: 1.35rem;
}
.profile-card strong {
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.profile-login-form {
width: min(100%, 24rem);
padding: 1.25rem;
}
}
.eyebrow {