"use client" import type React from "react" import { useState } from "react" import { Button } from "./ui/button" import { Input } from "./ui/input" import { Label } from "./ui/label" import { Lock, User, AlertCircle, Server } from "lucide-react" import { getApiUrl } from "../lib/api-config" import Image from "next/image" interface LoginProps { onLogin: () => void } export function Login({ onLogin }: LoginProps) { const [username, setUsername] = useState("") const [password, setPassword] = useState("") const [error, setError] = useState("") const [loading, setLoading] = useState(false) const handleLogin = async (e: React.FormEvent) => { e.preventDefault() setError("") if (!username || !password) { setError("Please enter username and password") return } setLoading(true) try { const response = await fetch(getApiUrl("/api/auth/login"), { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username, password }), }) const data = await response.json() if (!response.ok) { throw new Error(data.error || "Login failed") } // Save token localStorage.setItem("proxmenux-auth-token", data.token) onLogin() } catch (err) { setError(err instanceof Error ? err.message : "Login failed") } finally { setLoading(false) } } return (
Sign in to access your dashboard
ProxMenux Monitor v1.0.1