From 5576a4c293efb48671d868cb84614a7a82f5525c Mon Sep 17 00:00:00 2001 From: Thisyahlen Date: Thu, 12 Dec 2024 11:37:03 +0800 Subject: [PATCH 1/3] feat: oidc implementation --- package-lock.json | 30 ++++++++------- package.json | 2 +- .../UserNavbarItem/item.desktop.tsx | 38 ++++++++++++++++++- .../Apiexplorer/LoginDialog/index.tsx | 7 +++- src/features/Callback/CallbackPage.tsx | 17 +++++++++ src/features/Callback/index.ts | 2 + src/features/Login/Login.tsx | 8 +++- .../dashboard/__tests__/dashboard.test.tsx | 5 +++ src/features/dashboard/dashboard.tsx | 3 +- src/hooks/useHandleLogin/index.tsx | 35 +++++++++++++++++ .../useLogout/__tests__/useLogout.test.tsx | 13 +++++++ src/hooks/useLogout/index.tsx | 13 +++---- src/pages/auth.tsx | 5 ++- src/pages/callback.tsx | 26 +++++++++++++ src/utils/__tests__/utils.test.ts | 31 ++++++++++++++- src/utils/index.ts | 26 +++++++++++-- 16 files changed, 227 insertions(+), 34 deletions(-) create mode 100644 src/features/Callback/CallbackPage.tsx create mode 100644 src/features/Callback/index.ts create mode 100644 src/hooks/useHandleLogin/index.tsx create mode 100644 src/pages/callback.tsx diff --git a/package-lock.json b/package-lock.json index 5d70b9391..cab213a02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { - "name": "deriv-api-docs", + "name": "@deriv/deriv-api-docs", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "deriv-api-docs", + "name": "@deriv/deriv-api-docs", "version": "1.0.0", "dependencies": { "@deriv-com/analytics": "^1.22.1", - "@deriv-com/auth-client": "^1.0.29", + "@deriv-com/auth-client": "^1.3.1", "@deriv-com/quill-ui": "^1.16.21", "@deriv/deriv-api": "^1.0.11", "@deriv/ui": "^0.8.0", @@ -2599,12 +2599,16 @@ } }, "node_modules/@deriv-com/auth-client": { - "version": "1.0.29", - "resolved": "https://registry.npmjs.org/@deriv-com/auth-client/-/auth-client-1.0.29.tgz", - "integrity": "sha512-4iBxaSKM9hu6qVHGUr4MHtik59j1ZIuvveRnSqAbqQgcQGzKfSLRwGJ53P/5lVByh9fIIyICpuxbTgaaYA4eXg==", + "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.37", + "@deriv-com/utils": "^0.0.42", + "js-cookie": "3.0.5", "oidc-client-ts": "^3.1.0" + }, + "optionalDependencies": { + "@rollup/rollup-linux-x64-gnu": "^4.27.3" } }, "node_modules/@deriv-com/quill-tokens": { @@ -2688,9 +2692,9 @@ } }, "node_modules/@deriv-com/utils": { - "version": "0.0.37", - "resolved": "https://registry.npmjs.org/@deriv-com/utils/-/utils-0.0.37.tgz", - "integrity": "sha512-+ngUvT+OqwblBoqkHcsbLtljjwOGIjjMpo5xLS5fwyhtNvBe8Rcq+140QV1j0xq9vlm2kmcowEKIVBq33imFmg==" + "version": "0.0.42", + "resolved": "https://registry.npmjs.org/@deriv-com/utils/-/utils-0.0.42.tgz", + "integrity": "sha512-4JhTpg0sQWCq94RSMGpuT/09bYSV8yO3WdunM2R84qxWNitRH/i4k/xfdleRVzX+xLSmMmJWlkbD6NAlP8U5eg==" }, "node_modules/@deriv/api-types": { "version": "1.0.292", @@ -6472,9 +6476,9 @@ } }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.24.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.24.0.tgz", - "integrity": "sha512-ZXFk7M72R0YYFN5q13niV0B7G8/5dcQ9JDp8keJSfr3GoZeXEoMHP/HlvqROA3OMbMdfr19IjCeNAnPUG93b6A==", + "version": "4.28.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.28.1.tgz", + "integrity": "sha512-fzgeABz7rrAlKYB0y2kSEiURrI0691CSL0+KXwKwhxvj92VULEDQLpBYLHpF49MSiPG4sq5CK3qHMnb9tlCjBw==", "cpu": [ "x64" ], diff --git a/package.json b/package.json index 6c854c79a..5a7c8fda2 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "dependencies": { "@deriv-com/quill-ui": "^1.16.21", "@deriv-com/analytics": "^1.22.1", - "@deriv-com/auth-client": "^1.0.29", + "@deriv-com/auth-client": "^1.3.1", "@deriv/deriv-api": "^1.0.11", "@radix-ui/react-tooltip": "^1.0.7", "@react-spring/web": "^9.7.3", diff --git a/src/components/UserNavbarItem/item.desktop.tsx b/src/components/UserNavbarItem/item.desktop.tsx index 7bbd9594d..8e3c4c894 100644 --- a/src/components/UserNavbarItem/item.desktop.tsx +++ b/src/components/UserNavbarItem/item.desktop.tsx @@ -12,6 +12,8 @@ import useDeviceType from '@site/src/hooks/useDeviceType'; import { IUserNavbarItemProps } from './item.types'; import styles from './UserNavbarItem.module.scss'; +import Cookies from 'js-cookie'; +import { useHandleLogin } from '@site/src/hooks/useHandleLogin'; interface IActionProps { handleClick: () => void; @@ -62,12 +64,16 @@ const DashboardActions: React.FC = ({ handleClick, isDesktop }) => const SignedInActions: React.FC = ({ handleClick, isDesktop }) => { const signedInButtonClasses = clsx('navbar__item', styles.UserNavbarItem, styles.SignedInButton); + const { handleLogin } = useHandleLogin({ + onClickLogin: handleClick, + }); + return (