Skip to content

Instantly share code, notes, and snippets.

@aloukissas
Created January 14, 2019 15:28
Show Gist options
  • Save aloukissas/9047dd784674261eb54c87150380d88e to your computer and use it in GitHub Desktop.
Save aloukissas/9047dd784674261eb54c87150380d88e to your computer and use it in GitHub Desktop.
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