I want to login using email and password from API. If the email and password in the API are correct, log in. When I use const adminUser it logs in. But I don't know how to login using the API
If the email and password entered by the user are the same as the email and password in my API, I want the LoginPage page to open.
import React, { useState } from "react";
import LoginForm from "./LoginForm";
export default function LoginApp() {
const adminUser = {
email: "admin@admin.com",
password: "123",
};
const [user, setUser] = useState({ email: "", password: "" });
const [error, setError] = useState("");
const Login = (details) => {
console.log(details);
if (details.email === adminUser.email && details.password === adminUser.password) {
console.log("Logged in")
setUser({
email:details.email,
password:details.password
})
}else{
console.log()
setError("Details do not match")
}
};
const Logout = () => {
setUser({
email:"", password:""
})
};
return (
<div className="LoginApp">
{user.email !== "" ? (
<div className="welcome">
<h2>
Welcome, <span>{user.email}</span>
</h2>
<button onClick={Logout}>Logout</button>
</div>
) : (
<LoginForm Login={Login} error={error}/>
)}
</div>
);
}