Closed neats-returns closed 3 years ago
Hey @neats-returns 👋 thanks for raising this. I'm not sure I understand the issue here. How would a user be the owner of a record if they weren't allowed to create it?
@neats-returns How would a user be the owner of a record if they weren't allowed to create it?
Hi ! Let's put it another way, I want to create a record on the table ChatInvitation from a lambda function through AppSync API. But I just want one person to be able to subscribe the onCreateChatInvitation subscription, and that's why I'm using the owner field.
I could also do {allow: owner, ownerField: "invitedUserId", operations: [read]}
The problem is that when I try to subscribe to the onCreateChatInvitation subscription I get this error : "Unauthorized","message": "Not Authorized to access onCreateChatInvitation on type Subscription"
Ah okay, I missed the part where you were performing the mutation in the lambda function. Thank you! I will try to reproduce this issue and see if I can either figure out how to do it properly or if this a bug that needs to be addressed.
To further my understanding of the issue, you were able to subscribe to creation mutations before adding the IAM provider to the model's auth directive?
Hi, sorry for the late reply. So I made it work by adding the rule rules following rule to my model: { allow: private, operations: [read] }
.
You also need to create a custom subscription because if the model is protected by a ownerField, the generated subscription will ask for it. The other interesting thing is that if you don't return every field when you're calling you're mutation, the subscription won't be fired.
@neats-returns Ah, nice work figuring it out! That behavior of needing to return every field sounds like DataStore might be enabled for the API? Is this true or are you only using API.graphql
?
Well I was using it before, by I disabled it with amplify update api
. I'm now only using API.graphql
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server *-help
channels or Discussions for those types of questions.
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
GraphQL API
Amplify Categories
auth, function, api
Environment information
Describe the bug
I created a model which is only readable by it's owner, and it's created by a mutation called by a lambda function:
But when I try to subscribe to the onCreateChatInvitation subscription I'm getting this error :
"Unauthorized","message": "Not Authorized to access onCreateChatInvitation on type Subscription"
This my subscription code:
Expected behavior
The owner should be able to subscribe to the onCreate subscription event though he don't have the operation [create]
Reproduction steps
amplify update api
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response