Skip to content

Commit

Permalink
fix: use nextauth-based authentication in header (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterckx committed Oct 29, 2024
1 parent 5885d17 commit cefc930
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { AuthenticationMenu } from "@databiosphere/findable-ui/lib/components/LAyout/components/Header/components/Content/components/Actions/components/Authentication/components/AuthenticationMenu/authenticationMenu";

Check failure on line 1 in app/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/authentication.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find module '@databiosphere/findable-ui/lib/components/LAyout/components/Header/components/Content/components/Actions/components/Authentication/components/AuthenticationMenu/authenticationMenu' or its corresponding type declarations.
import { RequestAuthentication } from "@databiosphere/findable-ui/lib/components/LAyout/components/Header/components/Content/components/Actions/components/Authentication/components/RequestAuthentication/requestAuthentication";

Check failure on line 2 in app/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/authentication.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find module '@databiosphere/findable-ui/lib/components/LAyout/components/Header/components/Content/components/Actions/components/Authentication/components/RequestAuthentication/requestAuthentication' or its corresponding type declarations.
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 ? (
<AuthenticationMenu
onLogout={onLogout}
userProfile={{
name: userProfile.name ?? "",
picture: userProfile.image ?? "",
}}
/>
) : (
<RequestAuthentication
closeMenu={closeMenu}
requestAuthorization={requestAuthentication}
/>
))}
</>
);
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions site-config/hca-atlas-tracker/local/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -46,6 +47,7 @@ export function makeConfig(browserUrl: string, portalUrl: string): SiteConfig {
},
header: {
announcements: announcementsConfig,
authenticationComponent: Authentication,

Check failure on line 50 in site-config/hca-atlas-tracker/local/config.ts

View workflow job for this annotation

GitHub Actions / build

Type '{ announcements: ComponentsConfig; authenticationComponent: ({ authenticationEnabled, closeMenu, }: AuthenticationProps) => JSX.Element; authenticationEnabled: true; logo: JSX.Element; navigation: [...]; }' is not assignable to type 'HeaderProps'.
authenticationEnabled: true,
logo: C.Logo({
alt: APP_TITLE,
Expand Down

0 comments on commit cefc930

Please sign in to comment.