GraphQL query on Front End with cognito user pools and IAM auth

1

I'm currently building a Web application that stores data on DynamoDB.

I need to perform some GraphQL queries that need auth users on the Cognito user pool. My application login users with the IAM auth but when I query some information, every response is null.

I'm looking for a way to query information after login retrieving the Cognito user (already retrieved in my app) and passing it to the query function. Is this possible?

All the GraphQL works correctly in the AppSync view tested with Cognito user pool auth and VTL resolvers.

I would like to achieve the same result on the front end but it seems like I'm missing something

1 Answer
0

Yes, it is possible to query information after logging in and passing the Cognito user to the query function. One way to do this is to include the Cognito user's JWT token in the Authorization header of the GraphQL request. This can be done by retrieving the JWT token from the Cognito user object after a successful login and including it in the headers of the GraphQL request. You may also need to configure your AppSync API to require authentication using the Cognito user pool, and to pass the JWT token as an argument to the resolvers that handle the GraphQL queries. This way, the resolvers will be able to access the user's identity and use it to determine what data to return in the response.

profile picture
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions