Skip to content

Commit

Permalink
Revert "Fix wrong logout handler usage in auth-client, added silent l…
Browse files Browse the repository at this point in the history
…ogout"
  • Loading branch information
ahmadtaimoor-deriv authored Dec 10, 2024
1 parent 5aab624 commit 2d6cd3d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 44 deletions.
42 changes: 2 additions & 40 deletions src/javascript/_common/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
} = require('@deriv-com/utils');
const Cookies = require('js-cookie');
const requestOidcAuthentication = require('@deriv-com/auth-client').requestOidcAuthentication;
const OAuth2Logout = require('@deriv-com/auth-client').OAuth2Logout;
const handlePostLogout = require('@deriv-com/analytics').handlePostLogout;
const Analytics = require('./analytics');

export const DEFAULT_OAUTH_LOGOUT_URL = 'https://oauth.deriv.com/oauth2/sessions/logout';
Expand Down Expand Up @@ -79,48 +79,10 @@ export const isOAuth2Enabled = () => {
};

export const getLogoutHandler = onWSLogoutAndRedirect => {
const oAuth2Logout = OAuth2Logout(onWSLogoutAndRedirect);
const oAuth2Logout = handlePostLogout(onWSLogoutAndRedirect);
return oAuth2Logout;
};

export const requestSingleLogout = async (onWSLogoutAndRedirect) => {
const _requestSingleLogout = async () => {
const isLoggedOutCookie = Cookies.get('logged_state') === 'false';
const clientAccounts = JSON.parse(localStorage.getItem('client.accounts') || '{}');
const isClientAccountsPopulated = Object.keys(clientAccounts).length > 0;
const isAuthEnabled = isOAuth2Enabled();
const isCallbackPage = window.location.pathname.includes('callback');
const isEndpointPage = window.location.pathname.includes('endpoint');

if (isLoggedOutCookie && isClientAccountsPopulated && isAuthEnabled && !isCallbackPage && !isEndpointPage) {
const logoutHandler = getLogoutHandler(onWSLogoutAndRedirect);
await logoutHandler(onWSLogoutAndRedirect);
}
};

const isGrowthbookLoaded = Analytics.isGrowthbookLoaded();
if (!isGrowthbookLoaded) {
let retryInterval = 0;
// this interval is to check if Growthbook is already initialised.
// If not, keep checking it (max 10 times) and SSO if conditions are met
const interval = setInterval(() => {
if (retryInterval > 10) {
clearInterval(interval);
} else {
const isLoaded = Analytics.isGrowthbookLoaded();
if (isLoaded) {
_requestSingleLogout();
clearInterval(interval);
} else {
retryInterval += 1;
}
}
}, 500);
} else {
_requestSingleLogout();
}
};

export const requestSingleSignOn = async () => {
const _requestSingleSignOn = async () => {

Check warning on line 87 in src/javascript/_common/auth.js

View workflow job for this annotation

GitHub Actions / Build and Test

Unexpected dangling '_' in '_requestSingleSignOn'

Check warning on line 87 in src/javascript/_common/auth.js

View workflow job for this annotation

GitHub Actions / Build and Test

Unexpected dangling '_' in '_requestSingleSignOn'

Check warning on line 87 in src/javascript/_common/auth.js

View workflow job for this annotation

GitHub Actions / build_and_deploy_preview_link

Unexpected dangling '_' in '_requestSingleSignOn'

Check warning on line 87 in src/javascript/_common/auth.js

View workflow job for this annotation

GitHub Actions / build_and_deploy_preview_link

Unexpected dangling '_' in '_requestSingleSignOn'

Check warning on line 87 in src/javascript/_common/auth.js

View workflow job for this annotation

GitHub Actions / build_and_deploy_preview_link

Unexpected dangling '_' in '_requestSingleSignOn'
// if we have previously logged in,
Expand Down
5 changes: 1 addition & 4 deletions src/javascript/app/base/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const scrollToTop = require('../../_common/scroll').scrollToTop;
const toISOFormat = require('../../_common/string_util').toISOFormat;
const Url = require('../../_common/url');
const Analytics = require('../../_common/analytics');
const { requestSingleSignOn, requestSingleLogout } = require('../../_common/auth');
const { requestSingleSignOn } = require('../../_common/auth');
const Chat = require('../../_common/chat.js').default;
const createElement = require('../../_common/utility').createElement;
const isLoginPages = require('../../_common/utility').isLoginPages;
Expand Down Expand Up @@ -101,10 +101,7 @@ const Page = (() => {
updateLinksURL('#content');
} else {
init();
// if the user has logged in previously, silent login
requestSingleSignOn();
// if the user has logged out previously, silent logout
requestSingleLogout(Client.sendLogoutRequest);
if (!isLoginPages()) {
Language.setCookie(Language.urlLang());
const url_query_strings = Url.paramsHash();
Expand Down

0 comments on commit 2d6cd3d

Please sign in to comment.