Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete sessionCallBlocked only by the same tab that added entry #279

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ee69c94
fix: delete sessionCallBlocked only by the same tab that added entry
bogdan-niculescu-sch Apr 15, 2024
ff16970
fix: code review
bogdan-niculescu-sch Apr 15, 2024
ecf4a73
Merge branch 'master' into limit-clear-local-storage-clear
bogdan-niculescu-sch Apr 17, 2024
4ba1228
fix auto-merge
bogdan-niculescu-sch Apr 17, 2024
8ad19eb
fix: update Identity, Cache descriptions
bogdan-niculescu-sch Apr 17, 2024
d245c62
fix: clean block on page load when redirecting
bogdan-niculescu-sch Apr 17, 2024
5b01f5a
fix: fix build
bogdan-niculescu-sch Apr 22, 2024
a612d7f
Merge branch 'master' into limit-clear-local-storage-clear
bogdan-niculescu-sch Apr 22, 2024
b75286d
fix: fix build + minor cleanup
bogdan-niculescu-sch Apr 29, 2024
2205c7e
fix: fix Cache usage
bogdan-niculescu-sch May 3, 2024
cabfcc9
fix: block all session service calls and refine blocking period
bogdan-niculescu-sch May 3, 2024
97595a0
fix: Do not cache redirect response
bogdan-niculescu-sch May 6, 2024
f113a76
fix: Implement retry mechanism if session calls are blocked
bogdan-niculescu-sch May 8, 2024
2baee16
refactor: Small cleanup
bogdan-niculescu-sch May 8, 2024
cc28641
refactor: whitespace cleanup
bogdan-niculescu-sch May 8, 2024
1144bf1
fix: add local storage lock for session service also
bogdan-niculescu-sch May 10, 2024
356991d
Revert "fix: add local storage lock for session service also"
bogdan-niculescu-sch May 10, 2024
7293238
fix: do not clear block on Identity initialisation
bogdan-niculescu-sch May 10, 2024
8bf20df
fix: navigate to session service page after getSession
bogdan-niculescu-sch May 10, 2024
784c923
fix: unblock session calls after redirect
bogdan-niculescu-sch May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,11 @@ describe('Identity', () => {

describe('session refresh full page redirect', ()=>{
test('should do redirect when session endpoint respond with redirectURL only', async () => {
mockSessionOkResponse(Fixtures.sessionNeedsToBeRefreshedResponse)

mockSessionOkResponse(Fixtures.sessionNeedsToBeRefreshedResponse);
const MOCK_TAB_ID = 1234;
const spy = jest.spyOn(Identity.prototype, '_getTabId');
spy.mockImplementation(() => MOCK_TAB_ID);
identity._tabId = MOCK_TAB_ID;

await identity.hasSession();

Expand Down
19 changes: 11 additions & 8 deletions src/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export class Identity extends EventEmitter {
this.log = log;
this.callbackBeforeRedirect = callbackBeforeRedirect;
this._sessionDomain = sessionDomain;
this._tabId = this._getTabId();

// Internal hack: set to false to always refresh from hassession
this._enableSessionCaching = true;
Expand All @@ -209,7 +210,7 @@ export class Identity extends EventEmitter {
this._setOauthServerUrl(env);
this._setGlobalSessionServiceUrl(env);

this._unblockSessionCall();
this._unblockSessionCallByTab();
}

/**
Expand All @@ -233,7 +234,7 @@ export class Identity extends EventEmitter {
* Checks if getting session is blocked
* @private
*
* @returns {boolean|void}
* @returns {number/null}
*/
_isSessionCallBlocked(){
return this.localStorageCache.get(SESSION_CALL_BLOCKED_CACHE_KEY);
Expand All @@ -246,11 +247,11 @@ export class Identity extends EventEmitter {
* @returns {void}
*/
_blockSessionCall(){
const SESSION_CALL_BLOCKED = true;
const SESSION_CALL_BLOCKED_BY_TAB = this._tabId;

this.localStorageCache.set(
SESSION_CALL_BLOCKED_CACHE_KEY,
SESSION_CALL_BLOCKED,
SESSION_CALL_BLOCKED_BY_TAB,
SESSION_CALL_BLOCKED_TTL
);
}
Expand All @@ -261,8 +262,10 @@ export class Identity extends EventEmitter {
*
* @returns {void}
*/
_unblockSessionCall(){
this.localStorageCache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
_unblockSessionCallByTab(){
if (this._isSessionCallBlocked() === this._tabId) {
this.localStorageCache.delete(SESSION_CALL_BLOCKED_CACHE_KEY);
}
}

/**
Expand Down Expand Up @@ -589,7 +592,7 @@ export class Identity extends EventEmitter {
}
let sessionData = null;
try {
sessionData = await this._sessionService.get('/v2/session', {tabId: this._getTabId()});
sessionData = await this._sessionService.get('/v2/session', {tabId: this._tabId});
} catch (err) {
if (err && err.code === 400 && this._enableSessionCaching) {
const expiresIn = 1000 * (err.expiresIn || 300);
Expand All @@ -605,7 +608,7 @@ export class Identity extends EventEmitter {

await this.callbackBeforeRedirect();

return this._sessionService.makeUrl(sessionData.redirectURL, {tabId: this._getTabId()});
return this._sessionService.makeUrl(sessionData.redirectURL, {tabId: this._tabId});
}

if (this._enableSessionCaching) {
Expand Down
Loading