doc: add useHistory and auth with userEmailand Password
This commit is contained in:
1 parent
d4751e156c
commit
b42fdbc0ca
1 file changed
+11
-1
+11
-1
@@ -1,10 +1,12 @@
|
|||||||
import React, { useState } from "react";
|
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";
|
import "./Login.css";
|
||||||
|
|
||||||
function Login() {
|
function Login() {
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
const signIn = (e) => {
|
const signIn = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -12,6 +14,14 @@ function Login() {
|
|||||||
|
|
||||||
const register = (e) => {
|
const register = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
auth
|
||||||
|
.createUserWithEmailAndPassword(email, password)
|
||||||
|
.then((auth) => {
|
||||||
|
if (auth) {
|
||||||
|
history.push("/");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => alert(error.message));
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<section className="login">
|
<section className="login">
|
||||||
|
|||||||
Reference in new issue
Block a user