Created
November 28, 2018 10:50
-
-
Save Necmttn/1be3f79571d97ec405df3b70b0cd86e9 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 Amplify, { Auth } from 'aws-amplify'; | |
import { withAuthenticator } from 'aws-amplify-react/dist/Auth'; | |
import AWSAppSyncClient from 'aws-appsync'; | |
import { ApolloProvider } from 'react-apollo'; | |
const client = new AWSAppSyncClient({ | |
url: 'https://xxxx.appsync-api.us-east-1.amazonaws.com/graphql', | |
region: 'us-east-1', | |
auth: { | |
// AWS Cognito User Pool | |
type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS, | |
jwtToken: async () => (await Auth.currentSession()).getIdToken().getJwtToken(), | |
// API KEY | |
type: AUTH_TYPE.API_KEY, | |
apiKey: 'xxxxxxxxxxxxx', | |
// AWS IAM | |
type: AUTH_TYPE.AWS_IAM | |
credentials: () => Auth.currentCredentials(), | |
}, | |
}); | |
const WithProvider = () => ( | |
<Router> | |
<ApolloProvider client={client}> | |
</Router> | |
); | |
export default withAuthenticator(WithProvider); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment