Skip to content

Instantly share code, notes, and snippets.

@Necmttn
Created November 28, 2018 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Necmttn/1be3f79571d97ec405df3b70b0cd86e9 to your computer and use it in GitHub Desktop.
Save Necmttn/1be3f79571d97ec405df3b70b0cd86e9 to your computer and use it in GitHub Desktop.
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