Prevent reconnects for mssql provider (#22825)

This commit is contained in:
Cheena Malhotra
2023-04-21 16:56:40 -07:00
committed by GitHub
parent c581b0285d
commit 2247d5de88
4 changed files with 25 additions and 7 deletions

View File

@@ -116,14 +116,15 @@ export class MsalCachePluginProvider {
*/
public async writeTokenToLocalCache(token: Token): Promise<void> {
let updateCount = 0;
let indexToUpdate = -1;
let cache: LocalAccountCache;
cache = JSON.parse(await this.readCache(this._localCacheConfiguration)) as LocalAccountCache;
if (cache?.tokens) {
cache.tokens.forEach(t => {
cache.tokens.forEach((t, i) => {
if (t.key === token.key && t.tenantId === token.tenantId && t.resource === token.resource
) {
// Update token
t = token;
indexToUpdate = i;
updateCount++;
}
});
@@ -139,6 +140,9 @@ export class MsalCachePluginProvider {
}
if (updateCount === 1) {
if (indexToUpdate !== -1) {
cache.tokens[indexToUpdate] = token;
}
await this.writeCache(JSON.stringify(cache), this._localCacheConfiguration);
}
else {