1

Hello I am using AWS AppSync as the backend graphQL db. I am using Cognito to manage login, users and authentication. I am using IAM to manage identity rules, and guest users.

here is my inilization code:

let appSyncConfig = try AWSAppSyncClientConfiguration(appSyncServiceConfig: AWSAppSyncServiceConfig(),
    credentialsProvider: AWSMobileClient.default(),
    cacheConfiguration: AWSAppSyncCacheConfiguration())

// Initialize the AWS AppSync client
let appSyncClient = try AWSAppSyncClient(appSyncConfig: appSyncConfig)
appSyncClient.apolloClient?.cacheKeyForObject = { $0["id"] }

NOTE:: that I use default configurations, since all required information are in awsconfiguration.json file

I am using the following functions from cognito to sign up users:

AWSCognitoIdentityUserPool.signUp

and follow a phone number verification, and at completion I use AWSMobileClient to sign in: AWSMobileClient.default().signIn

THE ISSUE is:

after signing in, all the AppSync queries/mutations works without any issue BUT

after arbitrary time (usually 5 minutes) or at restarting the app

any AppSync queries/mutations that requires authorization RETURNS 401 (not authorized).

this issue continues until (what I think) the next time access/id tokens are refreshed (our configuration 1.5 hours), and the issue appears again after (5 min or restart).

Ala'a Al Hallaq
  • 455
  • 5
  • 11

1 Answers1

0

Whenever you receive 401 unauthorized, you should prompt the user to sign-in again. If this is happening very frequently and unexpectedly then there may be a bug in the SDK.

Feel free to open an issue over https://github.com/awslabs/aws-mobile-appsync-sdk-ios/issues to better help faciliate debugging your issue.

Lawmicha
  • 147
  • 6