/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: MIT-0 */ import * as React from "react"; import { I18n } from "@aws-amplify/core"; import { withAuthenticator } from "@aws-amplify/ui-react"; import { TopNavigation, TopNavigationProps } from "@cloudscape-design/components"; type NavbarProps = React.PropsWithChildren<{ signOut: () => void; user: { username: string; signInUserSession: { accessToken: { payload: { [key: string]: string[] }; }; }; }; }>; function Navbar({ signOut, user }: NavbarProps) { const { payload } = user.signInUserSession.accessToken; const groups = payload["cognito:groups"] || []; const isAdmin = groups.includes("admin"); const utilities:TopNavigationProps.Utility[] = []; function handleProfileClick(id: any): void { if (id === "signout") { signOut(); } } utilities.push({ type: "button", text: I18n.get("Sessions"), href: "/", external: false }); if (isAdmin) { utilities.push({ type: "button", iconName: "settings", text: I18n.get("Admin"), href: "/admin", external: false }); } utilities.push({ type: "menu-dropdown", text: user.username, iconName: "user-profile", items: [ { id: "signout", text: I18n.get("Sign out") } ], onItemClick: ({detail}) => handleProfileClick(detail.id) }); return ( ); } export default withAuthenticator(Navbar, { hideSignUp: true, });