From 2d6cd3dece57c281c59f6639ef1bc5fee26d79b9 Mon Sep 17 00:00:00 2001 From: ahmadtaimoor-deriv <129935294+ahmadtaimoor-deriv@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:52:34 +0800 Subject: [PATCH] Revert "Fix wrong logout handler usage in auth-client, added silent logout" --- src/javascript/_common/auth.js | 42 ++------------------------------- src/javascript/app/base/page.js | 5 +--- 2 files changed, 3 insertions(+), 44 deletions(-) diff --git a/src/javascript/_common/auth.js b/src/javascript/_common/auth.js index 88f7c8353ec..41c4d303068 100644 --- a/src/javascript/_common/auth.js +++ b/src/javascript/_common/auth.js @@ -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'; @@ -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 () => { // if we have previously logged in, diff --git a/src/javascript/app/base/page.js b/src/javascript/app/base/page.js index 45ae4e30770..89136eab72a 100644 --- a/src/javascript/app/base/page.js +++ b/src/javascript/app/base/page.js @@ -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; @@ -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();