import React, {useContext, useEffect, useState} from "react"; import {Link} from "react-router-dom"; import {useHttp} from "../hooks/http.hook"; import {useMessage} from "../hooks/message.hook"; import {AuthContext} from "../context/AuthContext"; export const AuthPage = () => { const auth = useContext(AuthContext) const {loading, error, request, clearError} = useHttp() const message = useMessage(); const [form, setForm] = useState( { username: '', password: '' }) const changeHandler = event => { setForm({ ...form , [event.target.name]: event.target.value}) } const loginHandler = async () => { try{ const data = await request('/api/auth/login', 'POST', {...form}) message(data.message) auth.login(data.token, data.userId) } catch (e){ } } useEffect(() => { message(error); clearError() },[error, message, clearError]) useEffect(() => { window.M.updateTextFields() }, []) return(

РОССЕТИ

Авторизация

) }