import { useState } from "react"; import Button from "../../pageElements/Button"; import { getAuth, signInWithEmailAndPassword } from "firebase/auth"; import { Link, useNavigate, createSearchParams } from "react-router-dom"; import "../../styles/login.scss"; const Login = () => { const navigate = useNavigate(); const auth = getAuth(); const [isBusy, setIsBusy] = useState(false); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [notice, setNotice] = useState(""); //const [searchParams, setSearchParams] = useSearchParams(); const userLogin = async (e) => { e.preventDefault(); if (isBusy) { return; } setIsBusy(true); setNotice(""); try { const userCredential = await signInWithEmailAndPassword( auth, email, password ); // Signed in userCredential?.user && navigate("/dashboard"); } catch (error) { if ( ["auth/invalid-login-credentials", "auth/invalid-email"].includes( error.code ) ) { setNotice("Incorrect email or password."); } else { setNotice(`Error occured (${error.code}).`); } } finally { setIsBusy(false); } }; const mode = "enterEmail"; function handleClick(e) { e.preventDefault(); //searchParams.set("mode", mode); //setSearchParams(searchParams); //navigate(`/passwordreset/?mode=enterEmail`); navigate({ pathname: "/passwordreset/", search: `?${createSearchParams({ mode: "enterEmail", })}`, }); } return (

Login to Novodraft

setEmail(e.target.value)} disabled={isBusy} >
setPassword(e.target.value)} disabled={isBusy} >
{"" !== notice && (
{notice}
)}
Create an account.
); }; export default Login;