Created
February 27, 2020 21:09
-
-
Save diegodario88/346d92172b7cd1e69eb4127d205b539d to your computer and use it in GitHub Desktop.
Warning: Can't perform a React state update on an unmounted component.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState } from 'react' | |
| import FormInput from '../form-input/form-input.component' | |
| import CustomButton from '../custom-button/custom-button.component' | |
| import { | |
| auth, | |
| createUserProfileDocument, | |
| } from '../../firebase/firebase.utils' | |
| import './sign-up.styles.scss' | |
| const SignUp = () => { | |
| const [userCredentials, setUserCredentials] = useState({ | |
| displayName: '', | |
| email: '', | |
| password: '', | |
| confirmPassword: '', | |
| }) | |
| const { | |
| displayName, | |
| email, | |
| password, | |
| confirmPassword, | |
| } = userCredentials | |
| const handleSubmit = async event => { | |
| event.preventDefault() | |
| if (password !== confirmPassword) { | |
| // eslint-disable-next-line quotes | |
| alert("password don't match") | |
| return | |
| } | |
| try { | |
| const { user } = await auth.createUserWithEmailAndPassword( | |
| email, | |
| password | |
| ) | |
| await createUserProfileDocument(user, { displayName }) | |
| //clear form | |
| setUserCredentials({ | |
| displayName: '', | |
| email: '', | |
| password: '', | |
| confirmPassword: '', | |
| }) | |
| } catch (error) { | |
| console.error(error) | |
| } | |
| } | |
| const handleChange = event => { | |
| const { name, value } = event.target | |
| setUserCredentials({ ...userCredentials, [name]: value }) | |
| } | |
| return ( | |
| <div className="sign-up"> | |
| <h2 className="title">I do not have a account</h2> | |
| <span>Sign up with your Email and Password</span> | |
| <form className="sign-up-form" onSubmit={handleSubmit}> | |
| <FormInput | |
| type="text" | |
| name="displayName" | |
| value={displayName} | |
| onChange={handleChange} | |
| label="Display Name" | |
| required | |
| /> | |
| <FormInput | |
| type="email" | |
| name="email" | |
| value={email} | |
| onChange={handleChange} | |
| label="Email" | |
| required | |
| /> | |
| <FormInput | |
| type="password" | |
| name="password" | |
| value={password} | |
| onChange={handleChange} | |
| label="Password" | |
| required | |
| /> | |
| <FormInput | |
| type="password" | |
| name="confirmPassword" | |
| value={confirmPassword} | |
| onChange={handleChange} | |
| label="Confirm Password" | |
| required | |
| /> | |
| <CustomButton type="submit"> SIGN UP </CustomButton> | |
| </form> | |
| </div> | |
| ) | |
| } | |
| export default SignUp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment