import { LockOutlined, UserOutlined } from "@ant-design/icons"; import { Button, Card, Form, Input, message, Typography } from "antd"; import React, { useState } from "react"; import { useNavigate } from "react-router"; import { useAuth } from "../../contexts/auth"; const { Title, Text } = Typography; interface LoginForm { username: string; password: string; } export const LoginPage: React.FC = () => { const { login, setup, authStatus, refreshAuthStatus } = useAuth(); const navigate = useNavigate(); const [isLoading, setIsLoading] = useState(false); const [isSetupMode, setIsSetupMode] = useState(false); const needsSetup = authStatus?.enabled && !authStatus?.has_users; const handleSubmit = async (values: LoginForm) => { setIsLoading(true); try { if (needsSetup || isSetupMode) { await setup(values.username, values.password); message.success("Admin account created successfully!"); } else { await login(values.username, values.password); message.success("Logged in successfully!"); } navigate("/"); } catch (err) { message.error(err instanceof Error ? err.message : "Authentication failed"); } finally { setIsLoading(false); } }; return (
Spoolman {needsSetup || isSetupMode ? "Create Admin Account" : "Sign in to continue"}
name="login" onFinish={handleSubmit} layout="vertical" requiredMark={false}> } placeholder="Username" size="large" autoFocus /> } placeholder="Password" size="large" /> {needsSetup && ( This is the first time setup. Create an admin account to get started. )}
); }; export default LoginPage;