perry
perry

Reputation: 41

Why do I get this error from aws amplify?

My react application using aws amplify authentication and api gives me the following error in the console when logging in.

DataStore - User is unauthorized to query syncFriendships with auth mode API_KEY. No data could be returned.

What info do I need to provide, and to who, to figure out how to fix this error message? .

Upvotes: 1

Views: 2314

Answers (3)

Nick Kanavati
Nick Kanavati

Reputation: 27

In aws-exports.js try changing "aws_appsync_authenticationType": "AWS_IAM", to whatever authentication type you are using like. For example, "aws_appsync_authenticationType": "API_KEY", https://docs.amplify.aws/lib/graphqlapi/authz/q/platform/js/

If this works you can make it permanent by running

amplify update api

then select graphql and update authorization modes.

Otherwise add additional authorization types in the AppSync schema: https://aws.amazon.com/blogs/mobile/using-multiple-authorization-types-with-aws-appsync-graphql-apis/

Upvotes: 1

Paritosh Agrawal
Paritosh Agrawal

Reputation: 284

Looks like error is during query from database. You are trying to access via graphQL via API_KEY which is expired. You need to generate new api_key and add it in aws-exports.js file. Follow this -

  1. Go to GraphQL from set up panel on Amplify studio.
  2. Open your resource from Deployed graphql resources.
  3. Go to settings on your api from left panel.
  4. In API Details look for the api key. If it show empty then you need to generate new one.
  5. Scroll down and find Default authorization mode box.
  6. create new api key by new button.
  7. copy and paste key value for aws_appsync_apiKey in aws-exports.js file.
  8. Thank me later.

Upvotes: 2

emch2
emch2

Reputation: 251

The user (you in your web browser) is not allowed to access the DataStore. You can either grant permissions for guest users or your user has to be signed in.

You can change the Authorization settings in Amplify Studio.

enter image description here

Upvotes: 0

Related Questions