-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathLogin.js
More file actions
57 lines (54 loc) · 1.51 KB
/
Login.js
File metadata and controls
57 lines (54 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { useContext,useState } from 'react';
import { Link, useHistory } from 'react-router-dom';
import Logo from '../../olx-logo.png';
import { FirebaseContext } from '../../store/Context';
import './Login.css';
function Login() {
const [email,setEmail]= useState('')
const [password,setPassword]= useState('')
const {firebase} = useContext(FirebaseContext)
const history = useHistory()
const handleLogin = (e)=>{
e.preventDefault()
firebase.auth().signInWithEmailAndPassword(email,password).then(()=>{
history.push('/')
}).catch((error)=>{
alert(error.message)
})
}
return (
<div>
<div className="loginParentDiv">
<img alt='img' width="200px" height="200px" src={Logo}></img>
<form onSubmit={handleLogin}>
<label htmlFor="fname">Email</label>
<br />
<input
className="input"
type="email"
value={email}
onChange={(e)=>setEmail(e.target.value)}
id="fname"
name="email"
/>
<br />
<label htmlFor="lname">Password</label>
<br />
<input
className="input"
type="password"
value={password}
onChange={(e)=>setPassword(e.target.value)}
id="lpass"
name="password"
/>
<br />
<br />
<button>Login</button>
</form>
<Link to="/signup">Signup</Link>
</div>
</div>
);
}
export default Login;