1

I created a books API with Amplify for an iOS app. I want the book table to have read access for both authenticated and unauthenticated users. Here's the schema:

type Book
  @model
  @searchable
  @auth(
    rules: [
      {allow: private, provider: userPools, operations: [read]},
      {allow: groups, groups: ["Admin"]}
    ]
  )
{
  id: ID!
  category: BookCategoryType!
  description: String
  groupsCanAccess: [String]!
  images: [Image!]
    @auth(rules: [
        {allow: groups, groupsField: "groupsCanAccess", operations: [read]},
        {allow: groups, groups: ["Admin"]}
    ])
  title: String!
}

However, when calling fetch from AWSAppSyncClient, I get the following error:

authenticationError(AWSMobileClient.AWSMobileClientError.notSignedIn(message: "User is not signed in, please sign in to use this API."))

The Cognito identity pool has Enable access to unauthenticated identities checked and there's an unauth IAM role.

What could be the problem?

Jameson
  • 6,400
  • 6
  • 32
  • 53
Benck
  • 515
  • 1
  • 5
  • 17
  • What is the "Default authorization mode" in your AppSync. Go to your AppSync API, and click on settings. Check what is your authorization mode, other than API Key, the user will have to login and and the API expects an auth token to serve the data – Praneet Nadkar May 15 '20 at 06:58
  • It's set to Amazon Cognito User Pool. If it's API Key, will I lose owner auth and group auth? Also, I just checked `AWSMobileClient.default().getAWSCredentials` and it returns credentials for the unauthenticated user. It just doesn't seem to get picked up by the API? – Benck May 15 '20 at 11:43
  • Since it is set to cognito user pool, it means that only authenticated users (from cognito) can access it. So while calling the API you need to send a auth header with a token to the api, so that it knows the request is coming from a validated source – Praneet Nadkar May 18 '20 at 07:22
  • Did you got what the problem was? I am also facing an issue, which is, I have an API which throws the above error at sometime and at sometime the API works fine. Kindly help me in this. Thanks in advance – Vishnu Prasannan Apr 23 '21 at 13:12

0 Answers0