import React, { useState } from 'react'; import { TextField, Button, Grid } from '@material-ui/core'; import { useAuth } from '../../hooks/useAuth'; import { post } from '../../requests'; const LoginForm: React.FC = () => { const { login } = useAuth(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const handleChangeUsername = (event: React.ChangeEvent) => { setUsername(event.target.value); }; const handleChangePassword = (event: React.ChangeEvent) => { setPassword(event.target.value); }; const handleSubmit = () => login(username, password) .then(success => success || post('/users', { username, password }) .then(() => login(username, password)) ); return ( ); }; export default LoginForm;