import {useEffect, useState} from 'react' import {signIn} from 'next-auth/client' import {useRouter} from 'next/router' import { Button, Container, FormControl, IconButton, Input, InputAdornment, InputLabel, LinearProgress, Snackbar, Typography } from '@material-ui/core' import {Visibility, VisibilityOff} from '@material-ui/icons' import MuiAlert from '@material-ui/lab/Alert' import {validateEmail} from '../../lib/utils/emails' function Alert(props) { return } function Koneksyon() { const [loginError, setError] = useState('') const [credentials, setCredentials] = useState({username: '', password: ''}) const [showPassword, setShowPassword] = useState(false) const [loading, setLoading] = useState(false) const [open, setOpen] = useState(true) const router = useRouter() const handleUpdate = update => { setCredentials({...credentials, ...update}) } const handleClick = async () => { setLoading(true) const response = await signIn('credentials', { redirect: false, ...credentials }) if (response.error) { setError(response.error) setLoading(false) } else if (response.ok) { setLoading(false) router.push('/kont') } } const handleClose = (event, reason) => { if (reason === 'clickaway') { return } setOpen(false) setError('') } useEffect(() => { if (loginError) { setOpen(true) } }, [loginError]) const handleClickShowPassword = () => { setShowPassword(!showPassword) } const handleMouseDownPassword = event => { event.preventDefault() } return ( Email handleUpdate({username: event.target.value})} /> Mot de passe {showPassword ? : } } onChange={event => handleUpdate({password: event.target.value})} /> {loading && } {loginError && ( {loginError} )} ) } export default Koneksyon