Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

amazon web services - Choosing "id" as ownedField in AppSync gives me "Not Authorized to access createUser on type User" error

I am using Amplify for iOS to create the models.

I am trying to set up storage of user information after logging in with AWS Cognito. Setting up all the connections would be a lot easier if the id of the user items was the same as their Cognito subs.

Before setting the ownerField to "id" (and leaving it as the default "owner"), I was able to create users through the AppSync console interface in AWS. After changing the ownerField to "id" however, it gives me the following error. I am sure I was doing it through User Pools and not through IAM when testing it out. Querying still works through even when ownerField is on "id"

{
  "data": {
    "createUser": null
  },
  "errors": [
    {
      "path": [
        "createUser"
      ],
      "data": null,
      "errorType": "Unauthorized",
      "errorInfo": null,
      "locations": [
        {
          "line": 2,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "Not Authorized to access createUser on type User"
    }
  ]
}

Here is the relevant GraphQL model structure

type User @model 
  @auth (
    rules: [
      { allow: owner, provider: userPools, ownerField: "id" },
      { allow: private, provider: iam, operations: [read] },
      { allow: public, provider: iam, operations: [read] }
    ]
  ) {
  id: ID!
  username: String
  firstName: String
  lastName: String
  email: String
  gender: String
  dateOfBirth: String
  userFollowers: [UserFollowing!] @connection(keyName: "byFollowers", fields: ["id"])
  userFollowing: [UserFollowing!] @connection(keyName: "byFollowing", fields: ["id"])
  brandFollowing: [BrandFollowing!] @connection(keyName: "byUser", fields: ["id"])
  createdItems: [Item!] @connection(keyName: "byUser", fields: ["id"])
  likedItems: [UserLikes!] @connection(keyName: "byUser", fields: ["id"])
  orders: [Order!] @connection(keyName: "byUser", fields: ["id"]) 
  profilePictureURL: String
}

Thanks!

question from:https://stackoverflow.com/questions/65649297/choosing-id-as-ownedfield-in-appsync-gives-me-not-authorized-to-access-create

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...