Additional fixes for firebase login. Capture basic local state.

This commit is contained in:
Patrick Fic
2019-12-06 17:55:00 -08:00
parent 0de42d3fee
commit 9f5753d1b7
15 changed files with 76 additions and 13 deletions

View File

@@ -0,0 +1,77 @@
import React from "react";
import { auth } from "../../firebase/firebase.utils";
import { Form, Icon, Input, Button, Alert } from "antd";
class SignInForm extends React.Component {
constructor() {
super();
this.state = {
errorMessage: null
};
}
handleSubmit = e => {
e.preventDefault();
this.props.form.validateFields(async (err, values) => {
if (!err) {
const { email, password } = values;
try {
await auth.signInWithEmailAndPassword(email, password);
this.props.form.resetFields();
} catch (error) {
this.setState({ ...this.state, errorMessage: error.message });
}
}
});
};
render() {
const { getFieldDecorator } = this.props.form;
const { errorMessage } = this.state;
return (
<Form onSubmit={this.handleSubmit} className="login-form">
<Form.Item label="E-mail">
{getFieldDecorator("email", {
rules: [
{
type: "email",
message: "Please enter a valid email."
},
{
required: true,
message: "Please your email."
}
]
})(<Input />)}
</Form.Item>
<Form.Item>
{getFieldDecorator("password", {
rules: [{ required: true, message: "Please enter your password." }]
})(
<Input
prefix={<Icon type="lock" style={{ color: "rgba(0,0,0,.25)" }} />}
type="password"
placeholder="Password"
/>
)}
</Form.Item>
<Form.Item>
<div className="login-form-forgot">Forgot password</div>
<Button
type="primary"
htmlType="submit"
className="login-form-button"
>
Log in
</Button>
</Form.Item>
{errorMessage ? (
<Alert message={errorMessage} type="error" />
) : (
null
)}
</Form>
);
}
}
export default Form.create({ name: "sign_in" })(SignInForm);