// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import './App.css'; import Amplify, { Auth, I18n } from 'aws-amplify'; import { withAuthenticator, AmplifySignOut } from '@aws-amplify/ui-react'; import React from 'react'; import { LargeNotification } from './views/shared/LargeNotification'; import Container from 'react-bootstrap/Container'; import Row from 'react-bootstrap/Row'; import Col from 'react-bootstrap/Col'; import Navbar from 'react-bootstrap/Navbar'; import { BrowserRouter as Router, Switch, Route } from 'react-router-dom'; import { Overview } from './views/overview/Overview'; import { MachineDetail } from './views/machines/MachineDetail'; declare var webUIAWSConfig: any; Amplify.configure(webUIAWSConfig); type AppProps = {}; type AppState = { email?: string }; class App extends React.Component { constructor(props: any) { super(props); this.state = {}; } async componentDidMount() { try { const user = await Auth.currentAuthenticatedUser(); if (user && user.attributes && user.attributes.email) { this.setState({ email: user.attributes.email }); } } catch (err) { console.error(err); // Reload if the user is no longer authenticated window.location.reload(); } // Check the accessToken to see if the user has logged out in another browser tab // If so, refresh the page so the user is logged out on all tabs try { window.addEventListener('storage', (evt) => { if (evt.storageArea === localStorage && evt.key) { if (evt.key.startsWith(`CognitoIdentityServiceProvider.${webUIAWSConfig.Auth.userPoolWebClientId}.`) && evt.key.endsWith('.accessToken')) { if (evt.oldValue && !evt.newValue) { window.location.reload(); } } } }) } catch (err) { console.error(err); } } render() { return (
{`${I18n.get('app.title')}`} {this.state.email} ( )} />
); } } export default withAuthenticator(App);