Created
January 14, 2019 15:28
-
-
Save aloukissas/9047dd784674261eb54c87150380d88e to your computer and use it in GitHub Desktop.
This file contains 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 from "react"; | |
import { createAppContainer } from "react-navigation"; | |
import Amplify, { Auth } from "aws-amplify"; | |
import { createRootNavigator } from "./router"; | |
import config from "./config"; | |
Amplify.configure({ | |
Auth: { | |
mandatorySignIn: true, | |
region: config.AWS.cognito.REGION, | |
userPoolId: config.AWS.cognito.USER_POOL_ID, | |
identityPoolId: config.AWS.cognito.IDENTITY_POOL_ID, | |
userPoolWebClientId: config.AWS.cognito.APP_CLIENT_ID | |
} | |
}); | |
class App extends React.Component { | |
state = { | |
isAuthenticated: false | |
}; | |
async componentDidMount() { | |
try { | |
await Auth.currentSession(); | |
this.setState({ isAuthenticated: true }); | |
} catch (error) { | |
if (error !== "No current user") { | |
console.log(error); | |
} | |
} | |
} | |
render() { | |
const RootNavigator = createRootNavigator(this.state.isAuthenticated); | |
const AppContainer = createAppContainer(RootNavigator); | |
return ( | |
<AppContainer /> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment