import { FormEvent, useState } from 'react' import { useNavigate } from 'react-router-dom' import toast from 'react-hot-toast' import { Film } from 'lucide-react' import { authAPI } from '../api/auth' import { useAuthStore } from '../stores/auth' // Single-form login screen. The first install seeds admin/admin123 — we // surface that hint when no JWT exists yet. export function LoginPage() { const navigate = useNavigate() const setSession = useAuthStore((s) => s.setSession) const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [loading, setLoading] = useState(false) const handleSubmit = async (e: FormEvent) => { e.preventDefault() setLoading(true) try { const data = await authAPI.login(username, password) setSession(data.token, data.user) toast.success(`欢迎回来,${data.user.username}`) navigate('/') } catch (err: unknown) { const msg = (err as { response?: { data?: { error?: string } } })?.response?.data?.error ?? '登录失败,请检查用户名与密码' toast.error(msg) } finally { setLoading(false) } } return (