Explorer
project
images
src
videos
favicon.ico
index.html
Dependencies
fuse.js@5.2.3
react-dom@16.13.1
react-router-dom@5.2.0
react@16.13.1
styled-components@5.1.0
Bootcamp
Study group
Collaborate with peers in your dedicated #study-group channel.
Code reviews
Submit projects for review using the /review
command in your #code-reviews channel
import React, { useState, useContext } from 'react';
import { useHistory } from 'react-router-dom';
import { FirebaseContext } from '../context/firebase';
import { Form } from '../components';
import { HeaderContainer } from '../containers/header';
import { FooterContainer } from '../containers/footer';
import * as ROUTES from '../constants/routes';
export default function Signin() {
const history = useHistory();
const { firebase } = useContext(FirebaseContext);
const [emailAddress, setEmailAddress] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const isInvalid = password === '' | emailAddress === '';
const handleSignin = (event) => {
event.preventDefault();
firebase
.auth()
.signInWithEmailAndPassword(emailAddress, password)
.then(() => {
history.push(ROUTES.BROWSE);
})
.catch((error) => {
setEmailAddress('');
setPassword('');
setError(error.message);
});
}
return (
<>
<HeaderContainer>
<Form>
<Form.Title>Sign In</Form.Title>
{error && <Form.Error>{error}</Form.Error>}
<Form.Base onSubmit={handleSignin} method="POST">
<Form.Input
placeholder="Email address"
value={emailAddress}
onChange={({ target }) => setEmailAddress(target.value)}
/>
<Form.Input
type="password"
value={password}
autoComplete="off"
placeholder="Password"
onChange={({ target }) => setPassword(target.value)}
/>
<Form.Submit disabled={isInvalid} type="submit">
Sign In
</Form.Submit>
<Form.Text>
New to Netflix? <Form.Link to="/signup">Sign up now.</Form.Link>
</Form.Text>
<Form.TextSmall>
This page is protected by Google reCAPTCHA.
</Form.TextSmall>
</Form.Base>
</Form>
</HeaderContainer>
<FooterContainer />
</>
)
}