"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || "http://127.0.0.1:18000"; export default function LoginPage() { const [login, setLogin] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [showPassword, setShowPassword] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); const router = useRouter(); const handleSubmit = async (e) => { e.preventDefault(); setError(""); setIsSubmitting(true); try { const res = await fetch(`${API_BASE_URL}/api/auth/login`, { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "include", body: JSON.stringify({ login, password }), }); if (!res.ok) { let message = "Неверный логин или пароль"; try { const data = await res.json(); if (data?.detail && typeof data.detail === "string") { message = data.detail; } } catch { // ignore malformed/non-json body } throw new Error(message); } router.push("/"); router.refresh(); } catch (err) { setError(err?.message || "Ошибка входа"); } finally { setIsSubmitting(false); } }; return (
AI Chat MVP

Вход в систему

setLogin(e.target.value)} type="text" placeholder="admin" required style={{ width: "100%", padding: "12px 16px", borderRadius: "8px", border: "1px solid var(--border-color)", fontSize: "15px", outline: "none", transition: "border-color 0.2s", }} onFocus={(e) => (e.target.style.borderColor = "var(--primary)")} onBlur={(e) => (e.target.style.borderColor = "var(--border-color)") } />
setPassword(e.target.value)} type={showPassword ? "text" : "password"} placeholder="••••••••" required style={{ width: "100%", padding: "12px 16px", borderRadius: "8px", border: "1px solid var(--border-color)", fontSize: "15px", outline: "none", transition: "border-color 0.2s", }} onFocus={(e) => (e.target.style.borderColor = "var(--primary)")} onBlur={(e) => (e.target.style.borderColor = "var(--border-color)") } />
{error ? (
{error}
) : null}
Вход доступен только для пользователей, созданных администратором.
); }