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.
Thank you for sharing the details and the code snippet.
From what you’ve described, it seems like the inconsistency in the
loginUsermethod triggering could be related to how token expiration and re-authentication are being handled in your implementation.A few things to check:
-
-
-
If you can, consider adding logging around token expiration detection andToken Expiry Detection: Ensure that your code reliably detects when the token has expired before attempting to call
loginUserto fetch a new one. Sometimes timing issues or cached token states might cause the method not to trigger consistently.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
loginUsercall, and retrying the failed requests once a new token is obtained.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.
loginUserinvocation 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!