Open PeterSchoell opened 3 months ago
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.
@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.)
Before opening, please confirm:
JavaScript Framework
Vue
Amplify APIs
DataStore
Amplify Version
v6
Amplify Categories
api
Backend
Amplify CLI
Environment information
Describe the bug
I have an application that uses AppSync DataStore with a model
Tenant
and anowner
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 https://github.com/aws-amplify/amplify-js/issues/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
await DataStore.start()
Code Snippet
Log output
aws-exports.js
"aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
Manual configuration
No response
Additional configuration
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response