Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataStore does not sync if using owner @auth #13769

Open
3 tasks done
PeterSchoell opened this issue Aug 29, 2024 · 2 comments
Open
3 tasks done

DataStore does not sync if using owner @auth #13769

PeterSchoell opened this issue Aug 29, 2024 · 2 comments
Assignees
Labels
DataStore Related to DataStore category pending-maintainer-response Issue is pending a response from the Amplify team.

Comments

@PeterSchoell
Copy link

Before opening, please confirm:

JavaScript Framework

Vue

Amplify APIs

DataStore

Amplify Version

v6

Amplify Categories

api

Backend

Amplify CLI

Environment information

"aws-amplify": "6.5.3",

Describe the bug

I have an application that uses AppSync DataStore with a model Tenant and an owner as authorisation method at field level.

When I submit a query via the AWS GUI, everything works as expected.

In the application, however, the sync throws a warning and no data is synchronised at all.

DataStore - User is unauthorised to query syncTenants with auth mode userPool. No data could be returned.

In #6625 switching to Cognito as the authentication method should help - however, this is already set for me.

"aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",

Expected behavior

All data is also synchronised via the datastore

Reproduction steps

  • Setup AppSync with given model
  • User Cognito as Auth method
  • In your client use DataStore and start DataStore await DataStore.start()

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


aws-exports.js

"aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",

Manual configuration

No response

Additional configuration

type Tenant @model  @auth(
      rules: [
        { allow: groups, groups: ["VerifiedUser"], operations: [read] }
        { allow: groups, groups: ["Admin"], operations: [create, update, read, delete] }
      ]
    ) 
  {
  id: ID! @primaryKey @auth(
      rules: [
        { allow: groups, groups: ["VerifiedUser"], operations: [read] }
        { allow: groups, groups: ["Admin"], operations: [create, update, read, delete] }
        { allow: owner, operations: [create, update, read, delete] }
      ]
    )
  tenantName: String
  tenantPlan: String
  tenantPayment: String
  tenantAddress: AWSJSON @auth(rules: [{ allow: owner, operations: [create, update, read, delete] }])
}

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@PeterSchoell PeterSchoell added the pending-triage Issue is pending triage label Aug 29, 2024
@cwomack cwomack added the DataStore Related to DataStore category label Aug 29, 2024
@chrisbonifacio chrisbonifacio removed the pending-triage Issue is pending triage label Aug 29, 2024
@chrisbonifacio
Copy link
Member

chrisbonifacio commented Aug 29, 2024

Hi @PeterSchoell 👋 thanks for raising this issue!

You mentioned that there is owner auth at the field level but it seems that your model level auth only allows users that belong to certain groups to read data from the table. Have you tried adding owner auth to the model level?

type Tenant @model @auth(
  rules: [
    { allow: groups, groups: ["VerifiedUser"], operations: [read] }
    { allow: groups, groups: ["Admin"], operations: [create, update, read, delete] }
+ { allow: owner, operations: [create, update, read, delete] } 
  ]
) {
  id: ID! @primaryKey
  tenantName: String
  tenantPlan: String
  tenantPayment: String
  tenantAddress: AWSJSON
  owner: String
}

With an owner auth rule, when records are created a owner field will be populated with the sub::username of the current user. Keep in mind that you can only be authorized to access records either as the owner OR belonging to an authorized group, but not both.

@PeterSchoell
Copy link
Author

PeterSchoell commented Aug 30, 2024

@chrisbonifacio Thank you for the quick reply.

The variant at model level to add the owner to the authentication works. The owner is always also in one of the two groups. The additional owner specification could restrict the operations (e.g. delete) here.

My case, however, is that only the owner should read the tenantAddress and no other user/group. As written, this works without problems in the AWS AppSync queries GUI, in the application via the datastore no element from the database is synchronised at all. (DataStore - User is unauthorised to query syncTenants with auth mode userPool. No data could be returned.)

@cwomack cwomack added pending-community-response Issue is pending a response from the author or community. pending-maintainer-response Issue is pending a response from the Amplify team. and removed pending-response pending-community-response Issue is pending a response from the author or community. labels Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DataStore Related to DataStore category pending-maintainer-response Issue is pending a response from the Amplify team.
Projects
None yet
Development

No branches or pull requests

3 participants