import { useMutation } from "@tanstack/react-query" import { useState } from "react" import { Loader2, Settings2 } from "lucide-react" import { toast } from "sonner" import type { AuthSession } from "@/lib/auth" import { signIn } from "@/lib/auth" import { getServerUrl, setServerUrl } from "@/lib/server-url" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" interface LoginPageProps { onLogin: (session: AuthSession) => void } export function LoginPage({ onLogin }: LoginPageProps) { const [serverUrlInput, setServerUrlInput] = useState(getServerUrl) const [email, setEmail] = useState("") const [password, setPassword] = useState("") const loginMutation = useMutation({ mutationFn: async () => { setServerUrl(serverUrlInput) return signIn(email, password) }, onSuccess(session) { onLogin(session) }, onError(err) { toast.error(err.message) }, }) function handleSubmit(e: React.FormEvent) { e.preventDefault() loginMutation.mutate() } const loading = loginMutation.isPending return (
Admin Dashboard Sign in to manage source configuration.
setServerUrlInput(e.target.value)} placeholder="http://localhost:3000" required />
setEmail(e.target.value)} placeholder="admin@aelis.local" required />
setPassword(e.target.value)} required />
) }