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
|
import React, {useState} from "react";
import FlexibleForm from "../components/FlexibleForm";
import benefitTwoImg from "../assets/img/benefit-two.png";
const Login = () => {
const [formData, setFormData] = useState({
email: "",
password: "",
});
const handleChange = (e) => {
const { name, value } = e.target;
setFormData((prevData) => ({
...prevData,
[name]: value,
}));
};
const handleSubmit = async (event) => {
event.preventDefault();
const { email, password } = formData;
const basicAuth = btoa(`${email}:${password}`)
console.log(basicAuth)
try {
const response = await fetch(process.env.REACT_APP_LOGIN_ROUTE, {
method: "POST",
headers: {
'Content-Type': 'application/json',
'Authorization': `Basic ${basicAuth}`,
},
});
if (response.ok) {
const data = await response
console.log("Login successful", data)
} else {
console.error("Login failed")
}
} catch (error) {
console.error('Error submitting form:', error);
}
}
return (
<>
<FlexibleForm
onFormSubmit={handleSubmit}
data={{
image: benefitTwoImg,
title: "Sign in to your account",
subtitle: "Sign in please",
formFields: [
{ label: "Email address", name: "email", type: "email", autoComplete: "email", required: true, value: formData.email, onChange: handleChange },
{ label: "Password", name: "password", type: "password", autoComplete: "current-password", required: true, value: formData.password, onChange: handleChange },
],
ctaText: "Login",
ctaLink: { text: "Don't have an account?", linkText: "Create an account instead!", url: "/sign-up" },
underneathButton: { url: "/forgot-password", text: "Forgot Password?" }
}}
/>
</>
);
};
export default Login;
|