-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathLogin.js
More file actions
59 lines (56 loc) · 1.54 KB
/
Login.js
File metadata and controls
59 lines (56 loc) · 1.54 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
58
59
import React, { useState,useContext } from 'react';
import {FirebaseContext} from '../../store/Context';
import Logo from '../../olx-logo.png';
import './Login.css';
import { useHistory } from 'react-router-dom';
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 width="200px" height="200px" src={Logo}></img>
<form onSubmit={handleLogin}>
<label htmlFor="fname">Email</label>
<br />
<input
className="input"
type="email"
id="fname"
value={email}
onChange={(e)=>setEmail(e.target.value)}
name="email"
defaultValue="John"
/>
<br />
<label htmlFor="lname">Password</label>
<br />
<input
className="input"
type="password"
id="lname"
value={password}
onChange={(e)=>setPassword(e.target.value)}
name="password"
defaultValue="Doe"
/>
<br />
<br />
<button>Login</button>
</form>
<a>Signup</a>
</div>
</div>
);
}
export default Login;