"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 isEmailValid = emailRegex.test(email); const isFormValid = isEmailValid && password.length > 0; const handleSubmit = (e) => { e.preventDefault(); if (!rememberMe) { setCheckboxError(true); return; } setCheckboxError(false); if (!isFormValid) return; try { login(email, password); // редирект сделает сам контекст } catch (err) { setAuthError(err.message); } }; return (
Тестовые аккаунты:
Пользователь: user@mail.com / user123
Волонтёр: vol@mail.com / vol123
Модератор: mod@mail.com / mod123