How to use AWS Amplify GraphQL APIs if I have access token of a logged in user?

Viewed 592

I am completely new to Amplify library. I have logged in my user using Cognito User Pool. I have the required access token (jwt token). How should I go about using AWS Amplify APIs for GraphQL using this access token?

Amplify.API.query
Amplify.API.mutate

Reading the documentation, it seems to me I have to login user using Amplify Auth only to use these APIs. In other words, how do I let Amplify know that I have access token of an authenticated user and allow me to use GrapQL APIs? Or authentication via Amplify Auth is the only way?

1 Answers

Amplify will handle this for you out-of-the-box.

After you authenticate the framework will take care of handling the JWT for you. If you want to see an easy enough implementation of authentication with Cognito + Amplify I recommend you this codebase:

https://www.amplifyauth.dev https://github.com/dabit3/amplify-auth-demo

After you have configured Amplify Auth and you create APIs using the Amplify CLI you'll be prompted if you want to create an authenticated or unauthenticated API.

On the client side, you'll just call the APIs using the Amplify JS library and the fact that you're authenticated or unauthenticated will be handled for you.

Related