import React from 'react' import './Login.css' import { Link, useHistory } from 'react-router-dom' import { provider, auth } from '../../firebase/firebaseConfig' import { useState } from 'react' import { toast, ToastContainer } from 'react-toastify'; function Login() { const history = useHistory() const [email, setEmail] = useState('') const [password, setPassword] = useState('') const login = (e) => { e.preventDefault() //stops refresh auth .signInWithEmailAndPassword(email, password) .then((auth) => { // redirect to homepage toast.success(`Login Successful, redirecting to homepage`); setTimeout(function () { history.push("/") }, 1000); }) .catch(e => { toast.error(`unable to login, please check your credentials`); setTimeout(function () { history.push("/login") }, 4000); console.warn(e.message) }) } const register = (e) => { e.preventDefault() //stops refresh auth .createUserWithEmailAndPassword(email, password) .then((auth) => { // create and redirect to homepage toast.success(`Registration Successful, redirecting to homepage`); setTimeout(function () { history.push("/") }, 1000); }) .catch(e => { toast.error(`unable to register, please check your credentials`); setTimeout(function () { history.push("/login") }, 4000); console.warn(e.message) }) } const loginWithGoogle = (e) => { e.preventDefault() //stops refresh auth.signInWithPopup(provider) .then(function (result) { // redirect to homepage toast.success(`Login Successful, redirecting to homepage`); setTimeout(function () { history.push("/") }, 1000); }) .catch(e => { toast.error(`unable to login, please check your credentials`); setTimeout(function () { history.push("/login") }, 4000); console.warn(e.message) }); } return (
) } export default Login