import { useState } from "react"; import { useLocation, useSearch, Link } from "wouter"; import { useLocalLogin } from "@workspace/api-client-react"; import { useQueryClient } from "@tanstack/react-query"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { PasswordInput } from "@/components/password-input"; import { loadCsrfToken } from "@/lib/csrf"; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; import { ThemeToggle } from "@/components/theme-toggle"; import { Wrench, AlertCircle } from "lucide-react"; import { useTranslation } from "react-i18next"; export default function Login() { const { t } = useTranslation(); const [, setLocation] = useLocation(); const search = useSearch(); const params = new URLSearchParams(search); const returnTo = params.get("returnTo") || "/"; const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const queryClient = useQueryClient(); const localLogin = useLocalLogin(); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); setError(null); localLogin.mutate( { data: { username, password } }, { onSuccess: () => { queryClient.invalidateQueries(); void loadCsrfToken(); setLocation(returnTo); }, onError: (err) => { setError(err.data?.error || err.message || t("auth.invalidCredentials")); }, }, ); }; return (
toolr

{t("auth.loginSubtitle")}

{t("auth.signIn")} {t("auth.loginDescription")}
setUsername(e.target.value)} placeholder="admin" autoFocus required />
setPassword(e.target.value)} required />
{error && (
{error}
)}
{t("notFound.backHome")}
); }