I want to create a User model and I want the User ID to always be equal to the Owner ID.
How to do this?
This is my schema.graphql file content:
type User @model {
id: ID! @default(value: @owner) # == owner
name: String!
description: String
birthday: AWSDateTime
}
Thank you
2
Answers
I had the same problem and found the solution highlighted below:
I’ve specified on the model level
@auth
rules to use theid
field as the "ownerField" and give other authenticated users a read access.Then on the field level, I’ve removed the
update
access to the owner (again using@auth
rules), so it is impossible to re-assign the record later on.for my case, I just added sub from Congnito User:
sub is retrieved from cognito thanks to Auth.currentAuthenticatedUser(), when you login for the first time a new user row is added to the dynamo table User.