User icon
@paradock 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
  • User icon
    don't think you're supposed to use json for the body
    • User icon
      qhar
    • User icon
      whgar am i the supposed t do
    • User icon
      ok look like darflen is being extremely picky with HTTP methods (fetch preflight sends a OPTIONS method request before doing the POST request)

      so you're basically screwed

      you can do:

      1) use XMLHttpRequest
      2) wait for me to fix this
    • User icon
      sadjnes
    • User icon
      xmlhttprequest doesnt work :<
    • User icon
      what error
    • User icon
      the same cors error :P
    • User icon
      pls fix :(
    • User icon
      ok i used that on darflen

      function get_data(url:string) {
      let response = await fetch(url, {
      method: "GET",
      cache: "no-cache",
      credentials: "include",
      mode: "cors",
      redirect: "follow",
      });

      return response.json();
      }
    • User icon
      yeah i think you need to add mode: "cors"
    • User icon
      nice!
    • User icon
      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)
      • User submitted image
    • User icon
      oops forgot to add the cors header back!
    • User icon
      nope still doesnt work
    • User icon
      same error has the one above?
    • User icon
      yup
    • User icon
      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
    • User icon
      fields variable should be a html form
  • User icon
    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