Skip to content

Instantly share code, notes, and snippets.

@aloukissas aloukissas/App.js
Created Jan 14, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.