Home > Mobile >  react js, it does not return the token code
react js, it does not return the token code

Time:10-06

react js, it does not return the token code. In the "postman" it works okay, a method "POST" and in the body I pass in "raw" the following json {"username": "Emanuel Lemos", "password": "123213"}. But when I do it in react js it doesn't return that, what am I doing wrong? Thank you

    const apiLogin = "http://america-emer-webcore.dev.emergencias.com.ar/api/login"

// Llamado a la api para obtener token
export const apiCallToken = async () => {
  const res = await fetch(apiLogin, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      username: "Emanuel Lemos",
      password: "123213",
    }),
  })
  const llave = await res.json()  // eslint-disable-next-line no-console
  console.log(llave)

  return llave

CodePudding user response:

could you post your React component code? Without it it's hard to understand what's the issue there. The apiCallToken function looks fine.

CodePudding user response:

Do you see any CORS issues? Maybe enable cors on the backend side. If you don't have access to the backend side and think the backend supports CORS, try a proxy on the frontend.

See this link to set up a proxy in react.

  • Related