diff --git a/package-lock.json b/package-lock.json index 54d2f1af2de..1a1593242d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@binary-com/binary-style": "^0.2.26", "@binary-com/webtrader-charts": "^0.6.2", "@deriv-com/analytics": "^1.26.1", - "@deriv-com/auth-client": "1.3.1", + "@deriv-com/auth-client": "1.3.3", "@deriv-com/quill-ui": "^1.16.2", "@deriv-com/utils": "^0.0.38", "@deriv/deriv-api": "^1.0.15", @@ -2527,9 +2527,9 @@ } }, "node_modules/@deriv-com/auth-client": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@deriv-com/auth-client/-/auth-client-1.3.1.tgz", - "integrity": "sha512-rS57tiQqogYPHnpGHM+1d6V8U0cUzmpD/fcK1A6jbeG9lr8Ntr6KYMOm07XOutG1P7joU/ppeR3Jpgn3SDzT/A==", + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@deriv-com/auth-client/-/auth-client-1.3.3.tgz", + "integrity": "sha512-LXp890lIZjZjSIs1OzHZCET/qQp9ACdLnbKOMXFAvqleNlUFZstlIhZIDYHTMorU3pclh3oG/wErZwRLNTMxkw==", "dependencies": { "@deriv-com/utils": "^0.0.42", "js-cookie": "3.0.5", diff --git a/package.json b/package.json index cc7d00bea33..027bdf7e43a 100644 --- a/package.json +++ b/package.json @@ -107,7 +107,7 @@ "@binary-com/binary-style": "^0.2.26", "@binary-com/webtrader-charts": "^0.6.2", "@deriv-com/analytics": "^1.26.1", - "@deriv-com/auth-client": "1.3.1", + "@deriv-com/auth-client": "1.3.3", "@deriv-com/quill-ui": "^1.16.2", "@deriv-com/utils": "^0.0.38", "@deriv/deriv-api": "^1.0.15", diff --git a/src/javascript/_common/auth.js b/src/javascript/_common/auth.js index 73bdbad0d12..41c4d303068 100644 --- a/src/javascript/_common/auth.js +++ b/src/javascript/_common/auth.js @@ -7,14 +7,13 @@ const { } = require('@deriv-com/utils'); const Cookies = require('js-cookie'); const requestOidcAuthentication = require('@deriv-com/auth-client').requestOidcAuthentication; +const handlePostLogout = require('@deriv-com/analytics').handlePostLogout; const Analytics = require('./analytics'); export const DEFAULT_OAUTH_LOGOUT_URL = 'https://oauth.deriv.com/oauth2/sessions/logout'; export const DEFAULT_OAUTH_ORIGIN_URL = 'https://oauth.deriv.com'; -const LOGOUT_HANDLER_TIMEOUT = 10000; - const SocketURL = { [URLConstants.derivP2pProduction]: 'blue.derivws.com', [URLConstants.derivP2pStaging] : 'red.derivws.com', @@ -80,62 +79,7 @@ export const isOAuth2Enabled = () => { }; export const getLogoutHandler = onWSLogoutAndRedirect => { - const isAuthEnabled = isOAuth2Enabled(); - let timeout; - - if (!isAuthEnabled) { - return onWSLogoutAndRedirect; - } - - const cleanup = () => { - clearTimeout(timeout); - - const iframe = document.getElementById('logout-iframe'); - if (iframe) iframe.remove(); - }; - - const onMessage = event => { - if (event.data === 'logout_complete') { - const domains = ['deriv.com', 'binary.sx', 'pages.dev', 'localhost']; - const currentDomain = window.location.hostname.split('.').slice(-2).join('.'); - if (domains.includes(currentDomain)) { - Cookies.set('logged_state', 'false', { - expires: 30, - path : '/', - secure : true, - }); - } - onWSLogoutAndRedirect(); - window.removeEventListener('message', onMessage); - cleanup(); - } - }; - - window.addEventListener('message', onMessage); - - const oAuth2Logout = () => { - if (!isAuthEnabled) { - onWSLogoutAndRedirect(); - return; - } - - let iframe = document.getElementById('logout-iframe'); - if (!iframe) { - iframe = document.createElement('iframe'); - iframe.id = 'logout-iframe'; - iframe.style.display = 'none'; - document.body.appendChild(iframe); - - timeout = setTimeout(() => { - onWSLogoutAndRedirect(); - window.removeEventListener('message', onMessage); - cleanup(); - }, LOGOUT_HANDLER_TIMEOUT); - } - - iframe.src = getOAuthLogoutUrl(); - }; - + const oAuth2Logout = handlePostLogout(onWSLogoutAndRedirect); return oAuth2Logout; }; diff --git a/src/javascript/app/pages/callback/callback.jsx b/src/javascript/app/pages/callback/callback.jsx index bdd7ed1559f..19100172b36 100644 --- a/src/javascript/app/pages/callback/callback.jsx +++ b/src/javascript/app/pages/callback/callback.jsx @@ -113,16 +113,6 @@ const CallbackContainer = () => { } getElementById('loading_link').setAttribute('href', redirect_url); - const domains = ['deriv.com', 'binary.sx', 'pages.dev', 'localhost']; - const currentDomain = window.location.hostname.split('.').slice(-2).join('.'); - if (domains.includes(currentDomain)) { - Cookies.set('logged_state', 'true', { - expires: 30, - path : '/', - secure : true, - }); - } - window.location.href = redirect_url; // need to redirect not using pjax }); };