i is having problems coding login authentication... i keep getting cors errors but i already did the stuff for the headers
const response = await fetch("https://api.darflen.com/auth/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({
email: fields[0].textContent,
password: fields[1].textContent
})
});
Comments
-
just sayin most of the api stuff is not tested from an user pov you should dm pardoc on discord for these things he will respond fast
so you're basically screwed
you can do:
1) use XMLHttpRequest
2) wait for me to fix this
function get_data(url:string) {
let response = await fetch(url, {
method: "GET",
cache: "no-cache",
credentials: "include",
mode: "cors",
redirect: "follow",
});
return response.json();
}
const fields = document.querySelectorAll('#loginpage input')
const response = await fetch("https://api.darflen.com/auth/login", {
method: "POST",
cache: "no-cache",
credentials: "include",
mode: "cors",
redirect: "follow",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
email: fields[0].value,
password: fields[1].value
})
});
if(!response.ok) {
throw new Error(response.message)
}
const responseData = await response.json()
console.log(responseData)
const fields = document.querySelectorAll('#loginpage')
const response = await fetch("https://api.darflen.com/auth/login", {
method: "POST",
cache: "no-cache",
mode: "cors",
redirect: "follow",
body: new FormData(fields)
});
if(!response.ok) {
throw new Error(response.message)
}
const responseData = await response.json()
console.log(responseData)
ok this code may not work but inputs are not json but application/x-www-form-urlencoded