Created
March 7, 2018 23:50
-
-
Save richardzcode/fb12af9f3832f412fd1faef1a5545d7b to your computer and use it in GitHub Desktop.
Render base on authentication state, aws-amplify.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
import Amplify, { Auth } from 'aws-amplify'; | |
import aws_exports from './aws-exports'; | |
import { withAuthenticator } from 'aws-amplify-react'; | |
Amplify.Logger.LOG_LEVEL = 'DEBUG'; | |
Amplify.configure(aws_exports); | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { authenticated: false } | |
} | |
componentDidMount() { | |
Auth.currentAuthenticatedUser() | |
.then(user => this.setState({ authenticated: true })) | |
.catch(err => this.setState({ authenticated: false })); | |
} | |
render() { | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<h1 className="App-title">Welcome to React</h1> | |
</header> | |
<div> | |
{ this.state.authenticated? 'In' : 'Out' } | |
</div> | |
</div> | |
); | |
} | |
} | |
// Auth.signOut(); | |
//export default withAuthenticator(App); | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment