File size: 3,013 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React from "react";
import "./SignIn.scss";
import Background from "../../Assets/Background.jpg";
import FormInput from "../../Components/FormInput/FormInput";
import CustomButton from "../../Components/CustomButton/CustomButton";
import { Link } from "react-router-dom";
import { faGoogle } from "@fortawesome/free-brands-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { signInWithGoogle } from "../../Firebase/firebase.utils";
import { auth } from "../../Firebase/firebase.utils";

class SignIn extends React.Component {
  constructor() {
    super();
    this.state = {
      email: "",
      password: ""
    };
  }

  handleSubmit = async event => {
    event.preventDefault();
    const { email, password } = this.state;

    try {
      await auth.signInWithEmailAndPassword(email, password);
      this.setState({ email: "", password: "" });
    } catch (error) {
      console.error(error);
    }
  };

  handleChange = event => {
    const { value, name } = event.target;

    this.setState({ [name]: value });
  };

  render() {
    return (
      <div className="signin">

        <div

          className="signin__bg"

          style={{ backgroundImage: `url(${Background})` }}

        />

        <div className="signin__container">

          <div className="signin__shadow">

            <h1 className="signin__title">Sign In</h1>



            <form

              action="POST"

              autoComplete="new-password"

              onSubmit={this.handleSubmit}

            >

              <FormInput

                name="email"

                type="email"

                value={this.state.email}

                handleChange={this.handleChange}

                label="Email"

                required

              />



              <FormInput

                name="password"

                type="password"

                value={this.state.password}

                handleChange={this.handleChange}

                label="Password"

                required

              />



              <div className="signin__btn-container">

                <div className="signin__btn">

                  <CustomButton type="submit" signin>

                    {" "}

                    Sign In{" "}

                  </CustomButton>

                  <CustomButton onClick={signInWithGoogle}>

                    <FontAwesomeIcon icon={faGoogle} className="signin__google-icon" />

                    Sign In With Google

                  </CustomButton>

                </div>

              </div>

            </form>

            <div className="signin__option">

              <span className="signin__option--newuser">New to Netflix?</span>

              <Link to="/signup" className="signin__option--link">

                Sign up now.

              </Link>

            </div>

          </div>

        </div>

      </div>
    );
  }
}

export default SignIn;