From 362d2d5c648ba0ad3f9f7b24090e0cff06c7648e Mon Sep 17 00:00:00 2001 From: adrienne-rio Date: Mon, 23 Sep 2024 15:22:05 +0800 Subject: [PATCH 01/13] feat: integrate auth-client for hydra logout functionality --- package-lock.json | 16 +++++++++++++++ package.json | 1 + src/components/AccountSwitcher/index.tsx | 14 ++++++++++++- .../useGrowthbookGetFeatureValue/index.tsx | 20 ++++++++++--------- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 719dae717..25da23c4d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "dependencies": { "@deriv-com/analytics": "^1.18.0", + "@deriv-com/auth-client": "^1.0.13", "@deriv/deriv-api": "^1.0.11", "@deriv/quill-icons": "^1.22.10", "@deriv/ui": "^0.8.0", @@ -2593,6 +2594,21 @@ "uuid": "dist/bin/uuid" } }, + "node_modules/@deriv-com/auth-client": { + "version": "1.0.13", + "resolved": "https://registry.npmjs.org/@deriv-com/auth-client/-/auth-client-1.0.13.tgz", + "integrity": "sha512-TR216AOpAkB8oHly+e9s16E2H2rZe8pt5gnt58Az8QB2pJ0h0Hfc+qUF9ZIV7Cbca7iOQs3ZYeviXEVRiUf80g==", + "dependencies": { + "@deriv-com/utils": "^0.0.33", + "react": "^18.3.1", + "react-dom": "^18.3.1" + } + }, + "node_modules/@deriv-com/utils": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/@deriv-com/utils/-/utils-0.0.33.tgz", + "integrity": "sha512-LzIpzMvfWhK9y06Qpe/HOB4pFCizk2wAyhv9I0s48Romq+d5MM1mmsuh5CvS4SnzzdLyuBy4rgXrOO3394HB7w==" + }, "node_modules/@deriv/api-types": { "version": "1.0.292", "resolved": "https://registry.npmjs.org/@deriv/api-types/-/api-types-1.0.292.tgz", diff --git a/package.json b/package.json index 129111baa..005f1fb6d 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ }, "dependencies": { "@deriv-com/analytics": "^1.18.0", + "@deriv-com/auth-client": "^1.0.13", "@deriv/deriv-api": "^1.0.11", "@deriv/quill-icons": "^1.22.10", "@deriv/ui": "^0.8.0", diff --git a/src/components/AccountSwitcher/index.tsx b/src/components/AccountSwitcher/index.tsx index 217a6f6ae..46148d206 100644 --- a/src/components/AccountSwitcher/index.tsx +++ b/src/components/AccountSwitcher/index.tsx @@ -1,6 +1,8 @@ import React, { useState, useRef } from 'react'; +import { useOAuth2 } from '@deriv-com/auth-client'; import { isNotDemoCurrency } from '@site/src/utils'; import useLogout from '@site/src/hooks/useLogout'; +import useGrowthbookGetFeatureValue from '@site/src/hooks/useGrowthbookGetFeatureValue'; import useAuthContext from '@site/src/hooks/useAuthContext'; import useOnClickOutside from '@site/src/hooks/useOnClickOutside'; import CurrencyIcon from '../CurrencyIcon'; @@ -10,8 +12,18 @@ import styles from './account_switcher.module.scss'; import SearchButton from '../SearchButton'; import Translate from '@docusaurus/Translate'; +type HydraBEApps = { + enabled_for: number[]; +}[]; + const AccountSwitcher = () => { + const [OAuth2EnabledApps, OAuth2EnabledAppsInitialised] = + useGrowthbookGetFeatureValue({ + featureFlag: 'hydra_be', + }); + const { logout } = useLogout(); + const { OAuth2Logout } = useOAuth2({ OAuth2EnabledApps, OAuth2EnabledAppsInitialised }, logout); const { currentLoginAccount } = useAuthContext(); const [is_toggle_dropdown, setToggleDropdown] = useState(false); @@ -57,7 +69,7 @@ const AccountSwitcher = () => {