amplify-js: DataStore subscriptions with combined authorization rules not working (bug)
Which Category is your question related to?
GraphQL Transform: @auth
Amplify CLI Version
4.17.1
What AWS Services are you utilizing?
- Amplify
- AppSync
- DynamoDB
- Cognito
Within the Amplify framework I am using:
- Auth
- DataStore
Provide additional details e.g. code snippets
I’ve created a React Native app in which users can create contacts. This is the schema:
type Contact
@model
@auth(rules: [
{ allow: owner },
{ allow: groups, groups: ["Admin"] }
])
{
id: ID!
gender: String
firstName: String
lastName: String
dateOfBirth: AWSDateTime
}
Within the app users can press a button to toggle the gender of a contact. The code looks like this:
const toggleGender = async () => {
await DataStore.save(
Contact.copyOf(userDetails, updated => {
updated.gender = updated.gender === 'male' ? 'female' : 'male';
}),
);
};
The problem:
I have one user logged in who’s part of the Admin group. I have another user logged in who created the contact. Both users correctly see the contact and the current value of the gender field. Whenever either of the users hit the toggle gender button, the other user doesn’t see the change. Basically it doesn’t sync. So it seems like the subscriptions aren’t working the way I want them too.
Whenever I remove { allow: owner } from the schema and make both users part of the Admin group, syncing works fine and both users can toggle the gender, and instantly see changes.
How can I make it work so subscriptions/syncing works with the above setup? Am I doing something wrong?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (4 by maintainers)
@iartemiev Just RN.
Here I am also having the same problem but with a slightly different rule
type Idea @model @auth (rules: [{allow: owner}])
Amplify CLI: 4.21.3 Datastore: 2.2.4