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 all 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
3 changes: 0 additions & 3 deletions src/cache.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default class Cache {
/**
* Get a value from cache (checks that the object has not expired)
* @param {string} key
* @private
* @returns {*} - The value if it exists, otherwise null
*/
private get;
Expand All @@ -23,14 +22,12 @@ export default class Cache {
* @param {string} key
* @param {*} value
* @param {Number} expiresIn - Value in milliseconds until the entry expires
* @private
* @returns {void}
*/
private set;
/**
* Delete a cache entry
* @param {string} key
* @private
* @returns {void}
*/
private delete;
Expand Down
3 changes: 0 additions & 3 deletions src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export default class Cache {
/**
* Get a value from cache (checks that the object has not expired)
* @param {string} key
* @private
* @returns {*} - The value if it exists, otherwise null
*/
get(key) {
Expand Down Expand Up @@ -124,7 +123,6 @@ export default class Cache {
* @param {string} key
* @param {*} value
* @param {Number} expiresIn - Value in milliseconds until the entry expires
* @private
* @returns {void}
*/
set(key, value, expiresIn = 0) {
Expand All @@ -145,7 +143,6 @@ export default class Cache {
/**
* Delete a cache entry
* @param {string} key
* @private
* @returns {void}
*/
delete(key) {
Expand Down
23 changes: 10 additions & 13 deletions src/identity.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,20 @@ export class Identity extends TinyEmitter {
*/
private _getTabId;
/**
* Checks if getting session is blocked
* Checks if calling get session is blocked
* @private
*
* @returns {boolean|void}
* @returns {string|null}
*/
private _isSessionCallBlocked;
/**
* Block calls to get session
* Block calls to get session. This is done to prevent concurrent calls which can log user out if session is refreshed by one of them
* @private
*
* @returns {void}
*/
private _blockSessionCall;
/**
* Unblocks calls to get session
* Unblocks calls to get session if the lock was put by the same tab
* @private
*
* @returns {void}
*/
private _unblockSessionCall;
Expand Down Expand Up @@ -106,7 +103,7 @@ export class Identity extends TinyEmitter {
private _setGlobalSessionServiceUrl;
_globalSessionService: RESTClient;
/**
* Emits the relevant events based on the previous and new reply from hassession
* Emits the relevant events based on the previous and new reply from {@link Identity#hasSession}
* @private
* @param {object} previous
* @param {object} current
Expand All @@ -121,7 +118,7 @@ export class Identity extends TinyEmitter {
private _closePopup;
popup: Window;
/**
* Set the Varnish cookie (`SP_ID`) when hasSession() is called. Note that most browsers require
* Set the Varnish cookie (`SP_ID`) when {@link Identity#hasSession} is called. Note that most browsers require
* that you are on a "real domain" for this to work — so, **not** `localhost`
* @param {object} [options]
* @param {number} [options.expiresIn] Override this to set number of seconds before the varnish
Expand Down Expand Up @@ -224,7 +221,7 @@ export class Identity extends TinyEmitter {
* @description This function calls {@link Identity#hasSession} internally and thus has the side
* effect that it might perform an auto-login on the user
* @throws {SDKError} If the user isn't connected to the merchant
* @return {Promise<string>} The `userId` field (not to be confused with the `uuid`)
* @return {number} The `userId` field (not to be confused with the `uuid`)
*/
getUserId(): Promise<string>;
/**
Expand Down Expand Up @@ -384,7 +381,7 @@ export type LoginOptions = {
* `password` (will force password confirmation, even if user is already logged in), `eid`. Those values might
* be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
* to verify AMR (Authentication Methods References) claim in ID token.
* Might also be used to ensure additional acr (sms, otp, eid) for already logged in users.
* Might also be used to ensure additional acr (sms, otp, eid) for already logged-in users.
* Supported value is also 'otp-email' means one time password using email.
*/
acrValues?: string;
Expand Down Expand Up @@ -453,7 +450,7 @@ export type SimplifiedLoginWidgetLoginOptions = {
* `password` (will force password confirmation, even if user is already logged in). Those values might
* be mixed as space-separated string. To make sure that user has authenticated with 2FA you need
* to verify AMR (Authentication Methods References) claim in ID token.
* Might also be used to ensure additional acr (sms, otp) for already logged in users.
* Might also be used to ensure additional acr (sms, otp) for already logged-in users.
* Supported value is also 'otp-email' means one time password using email.
*/
acrValues?: string;
Expand Down Expand Up @@ -621,7 +618,7 @@ export type HasSessionFailureResponse = {
};
export type SimplifiedLoginData = {
/**
* - Deprecated: User UUID, to be be used as `loginHint` for {@link Identity#login}
* - Deprecated: User UUID, to be used as `loginHint` for {@link Identity#login}
*/
identifier: string;
/**
Expand Down
Loading
Loading