Sometimes `loginUser` method not triggering when token expired | Community
Skip to main content

Sometimes `loginUser` method not triggering when token expired

  • October 27, 2025
  • 1 reply
  • 0 views

Lyet

I am having some issues when the token expires, and sometimes the “loginUser” method calls my API endpoint to get the new token, and other times it does not.

Why is this happening? Am I doing something wrong?


zE('messenger', 'loginUser', function (callback: any) {

generateZendeskToken()

.then(response => {

callback(response.data.result);

})

.catch(() => {

callback(null);

});

 

First picture is calling the new token.
The second one is not.


 

1 reply

Elaine14
  • December 30, 2025
Hi Lyet,
 
Thank you for sharing the details and the code snippet.
 
From what you’ve described, it seems like the inconsistency in the loginUser method triggering could be related to how token expiration and re-authentication are being handled in your implementation.
 
A few things to check:
 
  1. Token Expiry Detection: Ensure that your code reliably detects when the token has expired before attempting to call loginUser to fetch a new one. Sometimes timing issues or cached token states might cause the method not to trigger consistently.

     

  2. Error Handling and Retry Logic: In the network requests where you’re seeing the 401 errors, confirm that your error handlers are properly catching these, triggering the loginUser call, and retrying the failed requests once a new token is obtained.

     

  3. Synchronous vs Asynchronous Calls: Make sure that token refresh and subsequent API calls are coordinated correctly so that no API requests are sent with an expired token while waiting for a new one.

     

If you can, consider adding logging around token expiration detection and loginUser invocation to help track when and why it’s not being called. Also, reviewing or sharing more of the code where these network requests are handled might help identify any race conditions or gaps.
 
Hope this points you in the right direction!