import axios from 'axios'; import { FormEvent, useContext } from 'react'; import { NavBar } from '../components/navbar'; import { CenteredPage } from '../components/page'; import { ToastContext, toastType } from '../components/toast'; import { Button, Input, Vierkant } from '../components/ui'; import ErrorOutlineIcon from '@material-ui/icons/ErrorOutline'; import ReportProblemOutlinedIcon from '@material-ui/icons/ReportProblemOutlined'; import VpnKeyIcon from '@material-ui/icons/VpnKey'; function submitLogin(event?: FormEvent, toast?: toastType) { event?.preventDefault(); var formData = { email: (document.getElementById('email') as HTMLInputElement).value, password: (document.getElementById('password') as HTMLInputElement).value, }; if ( !formData.email || !formData.password ) { toast({ message: 'Vul alsjeblieft alle velden in!', type: 'error', icon: }); return; } axios({ method: 'post', url: `${window.location.origin}/api/auth/login`, headers: { 'content-type': 'application/json' }, data: formData, }) .then(() => window.location.pathname = '/') .catch(error => { if (error.response.status === 401) { toast({ message: 'Verkeerde gebruikersnaam of wachtwoord!', type: 'error', icon: }); return; } toast({ message: 'Er is iets fout gegaan', type: 'error', icon: }); }); } export default function LoginPage() { var { toast } = useContext(ToastContext); return (
submitLogin(e, toast)}>
); }