Files
tool-evaluator/artifacts/toolrate/src/pages/login.tsx
T
opencode cd4efd16f6
Build & Push Docker Image / build (push) Successful in 2m33s
feat(toolrate): rebrand to toolr + logo links home
- visible brand text changed to toolr (sidebar, mobile header, topbar
  fallback, login, 404, home heading, index.html title/og/twitter meta)
- brand logo now links to / in sidebar, mobile header, login, 404
- internal identifiers unchanged: package name, localStorage key
2026-08-01 20:20:01 +02:00

113 lines
3.8 KiB
TypeScript

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 { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card";
import { ThemeToggle } from "@/components/theme-toggle";
import { Wrench, AlertCircle } from "lucide-react";
export default function Login() {
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<string | null>(null);
const queryClient = useQueryClient();
const localLogin = useLocalLogin();
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
setError(null);
localLogin.mutate(
{ data: { username, password } },
{
onSuccess: () => {
queryClient.invalidateQueries();
setLocation(returnTo);
},
onError: (err) => {
setError(err.data?.error || err.message || "Invalid username or password");
},
},
);
};
return (
<div className="min-h-screen bg-background flex items-center justify-center p-4">
<div className="absolute top-4 right-4">
<ThemeToggle />
</div>
<div className="w-full max-w-sm space-y-6">
<div className="flex flex-col items-center gap-2 text-center">
<Link href="/" className="flex items-center gap-2 text-primary font-bold text-2xl">
<Wrench className="w-7 h-7" />
<span>toolr</span>
</Link>
<p className="text-muted-foreground text-sm">Sign in to your account</p>
</div>
<Card>
<CardHeader className="pb-4">
<CardTitle className="text-lg">Sign in</CardTitle>
<CardDescription>Enter your credentials to continue</CardDescription>
</CardHeader>
<CardContent>
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="username">Username</Label>
<Input
id="username"
type="text"
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder="admin"
autoFocus
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="password">Password</Label>
<Input
id="password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
</div>
{error && (
<div className="flex items-center gap-2 text-destructive text-sm rounded-md bg-destructive/10 px-3 py-2">
<AlertCircle className="w-4 h-4 shrink-0" />
{error}
</div>
)}
<Button
type="submit"
className="w-full"
disabled={localLogin.isPending}
>
{localLogin.isPending ? "Signing in..." : "Sign in"}
</Button>
</form>
</CardContent>
</Card>
<div className="text-center">
<Link href="/" className="text-sm text-muted-foreground hover:text-primary transition-colors">
Back to Home
</Link>
</div>
</div>
</div>
);
}