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

Revert "Fix wrong logout handler usage in auth-client, added silent logout" #879

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@
} = 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,50 +79,12 @@
};

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,
// this cookie will be set by the Callback page (which is exported from @deriv-com/auth-client library) to true when we have successfully logged in from other apps
const isLoggedInCookie = Cookies.get('logged_state') === 'true';
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
Loading