"use client"; import React, { useState } from "react"; import { useRouter } from "next/navigation"; import { useAuth } from "../app/context/AuthContext"; const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; const AuthPage = () => { const router = useRouter(); const { login } = useAuth(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [rememberMe, setRememberMe] = useState(false); const [checkboxError, setCheckboxError] = useState(false); const [authError, setAuthError] = useState(""); const [isSubmitting, setIsSubmitting] = useState(false); const isEmailValid = emailRegex.test(email); const isFormValid = isEmailValid && password.length > 0; const handleSubmit = async (e) => { e.preventDefault(); if (!rememberMe) { setCheckboxError(true); return; } setCheckboxError(false); if (!isFormValid) return; try { setAuthError(""); setIsSubmitting(true); await login(email, password); // теперь это async } catch (err) { setAuthError(err.message || "Неверный логин или пароль"); setIsSubmitting(false); } }; return (
Тестовые аккаунты (если настроены на бэке):
Пользователь: user@mail.com / user123123
Волонтёр: vol@mail.com / vol123123
Модератор: mod@mail.com / mod123123