diff --git a/app/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/authentication.tsx b/app/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/authentication.tsx new file mode 100644 index 00000000..1b83d26b --- /dev/null +++ b/app/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/authentication.tsx @@ -0,0 +1,42 @@ +import { AuthenticationMenu } from "@databiosphere/findable-ui/lib/components/LAyout/components/Header/components/Content/components/Actions/components/Authentication/components/AuthenticationMenu/authenticationMenu"; +import { RequestAuthentication } from "@databiosphere/findable-ui/lib/components/LAyout/components/Header/components/Content/components/Actions/components/Authentication/components/RequestAuthentication/requestAuthentication"; +import { signOut } from "next-auth/react"; +import { useRouter } from "next/router"; +import { useCallback } from "react"; +import { useAuthentication } from "../../../../../../../../../../hooks/useAuthentication/useAuthentication"; + +export interface AuthenticationProps { + authenticationEnabled?: boolean; + closeMenu: () => void; +} + +export const Authentication = ({ + authenticationEnabled, + closeMenu, +}: AuthenticationProps): JSX.Element => { + const { isAuthenticated, requestAuthentication, userProfile } = + useAuthentication(); + const router = useRouter(); + const onLogout = useCallback((): void => { + signOut({ callbackUrl: window.location.origin + router.basePath }); + }, [router]); + return ( + <> + {authenticationEnabled && + (isAuthenticated && userProfile ? ( + + ) : ( + + ))} + + ); +}; diff --git a/package-lock.json b/package-lock.json index f62a7d7e..283863fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,7 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-hook-form": "^7.51.2", + "react-idle-timer": "^5.7.2", "react-window": "1.8.9", "string-strip-html": "^13.4.8", "uuid": "8.3.2", @@ -16648,7 +16649,6 @@ "version": "5.7.2", "resolved": "https://registry.npmjs.org/react-idle-timer/-/react-idle-timer-5.7.2.tgz", "integrity": "sha512-+BaPfc7XEUU5JFkwZCx6fO1bLVK+RBlFH+iY4X34urvIzZiZINP6v2orePx3E6pAztJGE7t4DzvL7if2SL/0GQ==", - "peer": true, "peerDependencies": { "react": ">=16", "react-dom": ">=16" diff --git a/package.json b/package.json index 929982b7..f8e54971 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-hook-form": "^7.51.2", + "react-idle-timer": "^5.7.2", "react-window": "1.8.9", "string-strip-html": "^13.4.8", "uuid": "8.3.2", diff --git a/site-config/hca-atlas-tracker/local/config.ts b/site-config/hca-atlas-tracker/local/config.ts index 13c1c024..d53d24aa 100644 --- a/site-config/hca-atlas-tracker/local/config.ts +++ b/site-config/hca-atlas-tracker/local/config.ts @@ -8,6 +8,7 @@ import { TEXT_HEADING_XLARGE, } from "@databiosphere/findable-ui/lib/theme/common/typography"; import * as C from "../../../app/components/index"; +import { Authentication } from "../../../app/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/authentication"; import { ROUTE } from "../../../app/routes/constants"; import { SiteConfig } from "../../common/entities"; import { announcementsConfig } from "./announcements/announcementsConfig"; @@ -46,6 +47,7 @@ export function makeConfig(browserUrl: string, portalUrl: string): SiteConfig { }, header: { announcements: announcementsConfig, + authenticationComponent: Authentication, authenticationEnabled: true, logo: C.Logo({ alt: APP_TITLE,