import React, { useState } from 'react'; import axios from 'axios'; const Login = ({ setAuth }) => { const [formData, setFormData] = useState({ username: '', password: '', }); const { username, password } = formData; const onChange = (e) => setFormData({ ...formData, [e.target.name]: e.target.value }); const onSubmit = async (e) => { e.preventDefault(); try { const res = await axios.post('/api/auth/login', formData); localStorage.setItem('token', res.data.token); setAuth(true); } catch (err) { console.error(err.response.data); } }; return (
); }; export default Login;