doc: add useHistory and auth with userEmailand Password

This commit is contained in:
Leon Xu
2022-05-07 12:55:34 -07:00
parent d4751e156c
commit b42fdbc0ca
+11 -1
View File
@@ -1,10 +1,12 @@
import React, { useState } from "react";
import { Link } from "react-router-dom";
import { Link, useHistory } from "react-router-dom";
import { auth } from "./firebaseInit";
import "./Login.css";
function Login() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const history = useHistory();
const signIn = (e) => {
e.preventDefault();
@@ -12,6 +14,14 @@ function Login() {
const register = (e) => {
e.preventDefault();
auth
.createUserWithEmailAndPassword(email, password)
.then((auth) => {
if (auth) {
history.push("/");
}
})
.catch((error) => alert(error.message));
};
return (
<section className="login">