/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ import { useCognitoAuthContext } from "@aws-northstar/ui"; import AppLayout from "@aws-northstar/ui/components/AppLayout"; import * as React from "react"; import { useEffect, useState } from "react"; import { NavItems } from "./navitems"; import Config from "../../config.json"; import Routes from "../Routes"; /** * Defines the App layout and contains logic for routing. */ const App: React.FC = () => { const [username, setUsername] = useState(); const [email, setEmail] = useState(); const { getAuthenticatedUser } = useCognitoAuthContext(); useEffect(() => { if (getAuthenticatedUser) { const authUser = getAuthenticatedUser(); setUsername(authUser?.getUsername()); authUser?.getSession(() => { authUser.getUserAttributes((_, attributes) => { setEmail(attributes?.find((a) => a.Name === "email")?.Value); }); }); } }, [getAuthenticatedUser, setUsername, setEmail]); return ( new Promise(() => { getAuthenticatedUser && getAuthenticatedUser()?.signOut(); window.location.href = "/"; }) } user={ username ? { username, email, } : undefined } > ); }; export default App;