Across multiple javascript projects, we use the @cognite/sdk. We observe some strange behaviour when it comes to authentication and see the Chrome network panel full of HTTP 401 calls. When debugging the issue, we see that the getToken method supplied to the CogniteClient class only gets called some times. And when it does, the code on our part successfully retrieves a valid token. This leads to some unwanted behaviour and the user sometimes needs to refresh the browser in order to correct the browser state.
I suspect the fact that we make a new instance of CogniteClient everytime we use it could be the culprit. I read from the source code baseCogniteClient.ts that the getToken function is not called each time in order to “To prevent calling `getToken` method multiple times in parallel”. Not that I am really able to follow this behaviour over multiple instances of the client.
Any pointers as to what might cause this problem?
const getToken = async () => {
// this code only hits some times
};
const client = new CogniteClient({
appId: 'YOUR APPLICATION NAME',
project,
getToken,
});