Untitled
unknown
javascript
3 years ago
1.1 kB
7
Indexable
const handleSubmit = async () => {
// Check if values are not empty
if (!credentials.email || !credentials.password) {
invalidCredentials.value.loginFailed = true;
invalidCredentials.value.errorMessage = "Email address or password invalid";
// TODO if credentials are incorrect, reset bot fields
}
// Send the request to API
const response = await fetch('http://127.0.0.1:8000/api/v1/auth/login', {
method: "POST",
headers: {
Accept: 'application/vnd.api+json',
'Content-Type': 'application/vnd.api+json'
},
// credentials: 'include',
body: JSON.stringify({
email: credentials.email,
password: credentials.password
})
});
// If the credentials are invalid
if (response.status === 401) {
invalidCredentials.value.loginFailed = true;
invalidCredentials.value.errorMessage = "Invalid email address or password ";
}
// Get user data
const user = await response.json();
console.log(user);
}Editor is loading...