Skip to content

Commit

Permalink
fix: Only cache mpid and is_loggeed_in from xhr.responseText (#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmi22186 authored Jan 30, 2024
1 parent 4740596 commit dd1920f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/identity-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ export const cacheIdentityRequest = (
const cacheKey = concatenateIdentities(method, identities);
const hashedKey = generateHash(cacheKey);

cache[hashedKey] = { responseText: xhr.responseText, status: xhr.status, expireTimestamp};
const { mpid, is_logged_in } = JSON.parse(xhr.responseText);
const cachedResponseText = {
mpid,
is_logged_in,
};

cache[hashedKey] = { responseText: JSON.stringify(cachedResponseText), status: xhr.status, expireTimestamp};
idCache.store(cache);
};

Expand Down
12 changes: 7 additions & 5 deletions test/src/tests-identity-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ describe('identity-utils', () => {
expect(cachedIdentityCall.status).to.equal(200);
expect(cachedIdentityCall.expireTimestamp).to.equal(currentTime);

const responseText = JSON.parse(cachedIdentityCall.responseText);
expect(responseText).to.deep.equal(identifyResponse);
const cachedResponseText = JSON.parse(cachedIdentityCall.responseText);

const expectedResponseText = {mpid: testMPID, is_logged_in: false};
expect(cachedResponseText).to.deep.equal(expectedResponseText);
});

it('should save a login request to local storage', () => {
Expand All @@ -184,7 +186,6 @@ describe('identity-utils', () => {
...identifyResponse,
is_logged_in: true,
};


const jsonString = JSON.stringify(loginResponse);

Expand Down Expand Up @@ -220,8 +221,9 @@ describe('identity-utils', () => {
expect(cachedLoginCall.status).to.equal(200);
expect(cachedLoginCall.expireTimestamp).to.equal(currentTime);

const responseText = JSON.parse(cachedLoginCall.responseText);
expect(responseText).to.deep.equal(loginResponse);
const cachedResponseText = JSON.parse(cachedLoginCall.responseText);
const expectedResponseText = {mpid: testMPID, is_logged_in: true};
expect(cachedResponseText).to.deep.equal(expectedResponseText);
});
});

Expand Down

0 comments on commit dd1920f

Please sign in to comment.