I am working on react project that connect a login form with an external API and attached below is my Login.js code and I have another Profile.js compo
async function loginUser(credentials) {
return fetch(" https://1app.com/api/qs/loginx", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(credentials),
}).then((data) => data.json());
}
export default function Signin() {
const classes = useStyles();
const [username, setUserName] = useState();
const [password, setPassword] = useState();
const handleSubmit = async (e) => {
e.preventDefault();
const response = await loginUser({
username,
password,
});
if ("accessToken" in response) {
swal("Success", response.message, "success", {
title: "Ok Good",
icon: "success"
}).then((value) => {
localStorage.setItem("accessToken", response["accessToken"]);
localStorage.setItem("user", JSON.stringify(response["user"]));
window.location.href = "/profile";
});
} else {
swal("Failed", response.message, "error");
}
};
}
and when I clicked on Sign in button, then it display this error in browser console and it doesn't display the error using another API