Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!