Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading 'updateToken') #152

Open
aryo opened this issue Mar 13, 2024 · 5 comments
Open

TypeError: Cannot read properties of undefined (reading 'updateToken') #152

aryo opened this issue Mar 13, 2024 · 5 comments

Comments

@aryo
Copy link

aryo commented Mar 13, 2024

We're following the example, where on tokenAboutToExpire we fetch a new token and call client.updateToken, but we're seeing a lot of these errors:

TypeError: Cannot read properties of undefined (reading 'updateToken')
  at call(node_modules/@twilio/conversations/builds/browser.js:9351:49)
  at tryCatch(node_modules/@twilio/conversations/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:45:16)
  at _invoke(node_modules/@twilio/conversations/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:133:17)
  at key(node_modules/@twilio/conversations/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:74:21)
  at asyncGeneratorStep(node_modules/@twilio/conversations/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:20)
  at _next(node_modules/@twilio/conversations/node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9)

We are thinking of try/catching client.updateToken so it doesn't die, but from reading the conversations js internals, it looks like internally Client._fpaToken won't get set due to the error. Would there be any bad side effects?

We're on @twilio/conversations 2.4.1.

@berkus
Copy link
Contributor

berkus commented Mar 14, 2024

This means your client is undefined. Probably not yet initialized.

@aryo
Copy link
Author

aryo commented Mar 14, 2024

@berkus the client is defined. the error is thrown internally from within Client:

image

we're using it the exact same way as in the example:

    client.on("tokenAboutToExpire", async () => {
      const token = await getToken();
      await client.updateToken(token);
    }

@berkus
Copy link
Contributor

berkus commented Apr 4, 2024

@kmorope pls take a look at this folks.

@kmorope
Copy link

kmorope commented Apr 12, 2024

Hi @aryo, I'm trying to replicate the scenario for the issue but gonna need further info on your tech stack, are you using CRA like the Twilio conversations demo app or another framework? I made some tests directly on the demo app changing the token TTL, but the client is always defined, even in cases where the TTL is defined in less than a minute.

@aryo
Copy link
Author

aryo commented Apr 29, 2024

@kmorope Sorry for late reply, but yeah we are using CRA and the client instance lifecycle is similar to the example. A slight difference is that we have more things that can trigger another deinitialization of the client (e.g. log out etc) and we shutdown the client after removing listeners:

client.removeAllListeners();
await client.shutdown();

For completeness here's our initialization sequence + tokenAboutToExpire registration:

const token = await getToken();
const client = new Client(token)

client.on("tokenAboutToExpire", async () => {
  const token = await getToken();
  await client.updateToken(token);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants