import { useState } from "react"; import { clearAuthHeader, getAuthHeader, setAuthHeader } from "../../auth/authStore"; import Button from "../ui/Button"; type LoginPageProps = { onSuccess: () => void; }; export default function LoginPage({ onSuccess }: LoginPageProps) { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); if (!username.trim()) { setError("Kullanici adi gerekli."); return; } setAuthHeader(username.trim(), password); try { const base = import.meta.env.VITE_API_BASE ?? "/api"; const authHeader = getAuthHeader(); const response = await fetch(`${base}/health`, { headers: { Authorization: authHeader ?? "" } }); if (!response.ok) { throw new Error("Yetkisiz"); } setError(null); onSuccess(); } catch (error) { clearAuthHeader(); setError("Giris basarisiz. Kullanici adi veya sifre hatali."); } }; return (

Memos

Notlarina erismek icin giris yap.

{error &&

{error}

}
); }