/** * Component: Admin Account Setup Step * Documentation: documentation/setup-wizard.md */ 'use client'; import { useState, useEffect } from 'react'; import { Button } from '@/components/ui/Button'; interface AdminAccountStepProps { adminUsername: string; adminPassword: string; onUpdate: (field: string, value: string) => void; onNext: () => void; onBack: () => void; } export function AdminAccountStep({ adminUsername, adminPassword, onUpdate, onNext, onBack, }: AdminAccountStepProps) { const [confirmPassword, setConfirmPassword] = useState(''); const [errors, setErrors] = useState<{ username?: string; password?: string; confirm?: string }>({}); const [allowWeakPassword, setAllowWeakPassword] = useState(false); // Fetch password policy useEffect(() => { const fetchPolicy = async () => { try { const response = await fetch('/api/auth/providers'); if (response.ok) { const data = await response.json(); setAllowWeakPassword(data.allowWeakPassword === true); } } catch { // Default to strict validation on error } }; fetchPolicy(); }, []); const validate = () => { const newErrors: { username?: string; password?: string; confirm?: string } = {}; // Validate username if (!adminUsername || adminUsername.length < 3) { newErrors.username = 'Username must be at least 3 characters'; } // Validate password if (!adminPassword) { newErrors.password = 'Password is required'; } else if (!allowWeakPassword && adminPassword.length < 8) { newErrors.password = 'Password must be at least 8 characters'; } // Validate password confirmation if (adminPassword !== confirmPassword) { newErrors.confirm = 'Passwords do not match'; } setErrors(newErrors); return Object.keys(newErrors).length === 0; }; const handleNext = () => { if (validate()) { onNext(); } }; return (
Set up your administrator account to manage the application
{errors.username}
)}This will be your local admin username (minimum 3 characters)
{errors.password}
)}{allowWeakPassword ? 'Choose a password' : 'Choose a strong password (minimum 8 characters)'}
{errors.confirm}
)}About Admin Accounts
This local admin account is separate from media server authentication. Use it to access admin settings and manage the application.