Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'clientToken')

Though the clientToken has been defined and assigned a value, it is showing undefined properties, why?

The API call has been working fine, the URL is fine, but still it showing this error, can anyone help me with this.

Below is the error detial.

 if (info && info.error) {
  26 |     setInfo({ ...info, error: info.error });
  27 |   } else {
> 28 |     const clientToken = info.clientToken;
     | ^  29 |     setInfo({ clientToken });
  30 |   }
  31 | });

getToken object is below.

  const getToken = (userId, token) => {
    getmeToken(userId, token).then(info => {
      // console.log("INFORMATION", info);
      if (info && info.error) {
        setInfo({ ...info, error: info.error });
      } else {
        const clientToken = info.clientToken;
        setInfo({ clientToken });
      }
    });
  };

getmeToken component below.

export const getmeToken = (userId, token) => {
    return fetch(` ${API}/payment/gettoken/${userId}`, {
        method: "GET",
        headers: {
            Accept: "application/json",
            "Content-Type": "application/json",
            Authorization: `Bearer ${token}`
        }
    }).then(response => {
        return response.json();
    })
    .catch(err => console.log(err))
}

Can anyone help me with this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In your else condition you're never checking if info has been defined and it most likely isn't. The issue probably doesn't come from clientToken itself but from info being undefined or null.

You can try to do something like this:

if (info) {
  if (info.error) {
    setInfo({ ...info, error: info.error });
  } else {
    const clientToken = info.clientToken;
    setInfo({ clientToken });
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda