enables SignUp with email

This commit is contained in:
Ruidy Nemausat 2020-04-23 22:53:24 +02:00
parent 6f11a3e2c0
commit 52f03d6027
3 changed files with 30 additions and 3 deletions

View file

@ -3,5 +3,6 @@
- [ ] Doc
- [ ] Tests
- [ ] PropTypes
- [ ] Material UI
- [ ] AuthSlice
- [ ] Redux thunk for validation

View file

@ -1,5 +1,5 @@
import React, { useState } from "react";
import { Link } from "react-router-dom";
import { Link, withRouter } from "react-router-dom";
import { Button, Form, FormGroup, Label, Input, Container } from "reactstrap";
import * as ROUTES from "../../constants/routes";
import { useFirebase } from "../../services/auth";
@ -18,6 +18,9 @@ const useStyles = () => ({
},
});
/**
* Page's layout
*/
export default function SignUpPage() {
const styles = useStyles();
return (
@ -28,7 +31,10 @@ export default function SignUpPage() {
);
}
export const SignUpForm = () => {
/**
* Holds the form state and validates the form.
*/
const SignUpFormBase = (props) => {
const [userName, setUserName] = useState("");
const [email, setEmail] = useState("");
const [password1, setPassword1] = useState("");
@ -37,9 +43,23 @@ export const SignUpForm = () => {
const auth = useFirebase();
const cleanFields = () => {
setUserName("");
setEmail("");
setPassword1("");
setPassword2("");
setError(null);
};
const handleSubmit = (e) => {
e.preventDefault();
auth.signInWithGoogle().then((res) => console.log(res.user));
auth
.createUserWithEmailAndPassword(email, password1)
.then(() => {
cleanFields();
props.history.push(ROUTES.APP);
})
.catch((err) => setError(err));
};
const isInvalid =
@ -99,6 +119,11 @@ const InputField = ({ id, label, set, type = "text" }) => {
);
};
/**
* Sign Up form final component. withRouter allows redirections.
*/
export const SignUpForm = withRouter(SignUpFormBase);
export const SignUpLink = () => (
<p>
Don't have an account yet? <Link to={ROUTES.SIGN_UP}>Sign Up</Link>

View file

@ -23,6 +23,7 @@ export default class Firebase {
}
provider = new app.auth.GoogleAuthProvider();
signInWithGoogle = () => this.auth.signInWithPopup(this.provider);
createUserWithEmailAndPassword = (email, password) =>