Skip to content

Commit c34bd12

Browse files
signUp component added, email and password based authentication added into firebase
1 parent a4017aa commit c34bd12

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class App extends Component {
2828
...snapshot.data()
2929
}
3030
}, ()=> {
31-
console.log(this.state.currentUser)
31+
console.log(this.state)
3232
})
3333
})
3434
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React from 'react'
22
import './sign-in-and-sign-up.styles.scss'
33
import SignInForm from '../../components/sign-in/sign-in.component'
4+
import SignUpForm from '../../components/sign-up/sign-up.component'
45
export default function signInAndSignUpPage() {
56
return (
67
<div className="sign-in-and-sign-up">
78
<SignInForm />
9+
<SignUpForm />
810
</div>
911
)
1012
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import React, { Component } from 'react'
2+
import FormInput from '../form-input/form-input.component'
3+
import customButton from '../custom-button/custom-button.component'
4+
import { auth, createUserProfileDocument } from '../../firebase/firebase.utils'
5+
import './sign-up.styles.scss'
6+
import CustomButton from '../custom-button/custom-button.component'
7+
8+
export default class SignUpForm extends Component {
9+
constructor(props) {
10+
super(props)
11+
12+
this.state = {
13+
displayName: '',
14+
email: '',
15+
password: '',
16+
confirmPassword: '',
17+
}
18+
}
19+
handleSubmit = async event => {
20+
event.preventDefault()
21+
const { displayName, email, password, confirmPassword } = this.state
22+
23+
if (password !== confirmPassword) {
24+
alert("passwords do not match")
25+
return
26+
}
27+
28+
try {
29+
const { user } = await auth.createUserWithEmailAndPassword(email, password)
30+
await createUserProfileDocument(user, { displayName })
31+
this.setState({
32+
displayName: '',
33+
email: '',
34+
password: '',
35+
confirmPassword: '',
36+
})
37+
} catch (error) {
38+
console.log(error)
39+
}
40+
}
41+
42+
handleChange = e => {
43+
const { name, value } = e.target
44+
this.setState({ [name]: value })
45+
}
46+
47+
render() {
48+
const { displayName, email, password, confirmPassword } = this.state
49+
return (
50+
<div className="sign-up">
51+
<h2 className="title">I do not have an account</h2>
52+
<span>Signup with your email and password</span>
53+
54+
<form action="" onSubmit={this.handleSubmit} className="sign-up-form">
55+
56+
<FormInput type='text'
57+
name='displayName'
58+
value={displayName}
59+
onChange={this.handleChange}
60+
label="Display Name"
61+
required
62+
/>
63+
<FormInput type='email'
64+
name='email'
65+
value={email}
66+
onChange={this.handleChange}
67+
label="Email-Id"
68+
required
69+
/>
70+
<FormInput type='password'
71+
name='password'
72+
value={password}
73+
onChange={this.handleChange}
74+
label="Password"
75+
required
76+
/>
77+
<FormInput type='password'
78+
name='confirmPassword'
79+
value={confirmPassword}
80+
onChange={this.handleChange}
81+
label="Confirm Password"
82+
required
83+
/>
84+
<CustomButton type="submit">SignUp</CustomButton>
85+
86+
</form>
87+
</div>
88+
)
89+
}
90+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.sign-up {
2+
display: flex;
3+
flex-direction: column;
4+
width: 380px;
5+
6+
.title {
7+
margin: 10px 0;
8+
}
9+
}

0 commit comments

Comments
 (0)