Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda