AWS Amplify 未经授权错误 - 未授权访问类型 [...]

zar*_*tra 7 aws-amplify

我有一个使用 google federate 登录的 AWS Amplify 应用程序。这是我的数据模型。

type TriadeMetric @model @auth(rules: [{allow: owner}]) {
  id: ID!
  NoteMetrics: [NoteMetric] @hasMany(indexName: "byTriadeMetric", fields: ["id"])
}

enum MetricEnum {
  ACCURACY
  DURATION
}

type NoteMetric @model @auth(rules: [{allow: owner}]) {
  id: ID!
  metricType: MetricEnum
  value: Float
  triademetricID: ID! @index(name: "byTriadeMetric")
  semitones: Int
}
Run Code Online (Sandbox Code Playgroud)

当我尝试使用创建新记录时

const triadeMetric = await DataStore.save(new TriadeMetric({}));
Run Code Online (Sandbox Code Playgroud)

我收到此警告消息:

[{"errorType":"Unauthorized","message":"Not Authorized to access onCreateTriade on type Triade"}]}

和这个错误:

{"errors":[{"errorType":"Unauthorized to access onCreateTriade on type Triade"}]}

zar*_*tra 17

I was using the wrong authentification type: In aws-exports.js I replaced "aws_appsync_authenticationType": "API_KEY" with "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS"

  • 更改 AWS AppSync AuthenticationType 最终对我有用。但就我而言,我的 aws-exports.js 有一条警告,阻止我直接编辑该文件“//警告:请勿编辑。此文件由 AWS Amplify 自动生成。它将被覆盖。” 这里的步骤 /sf/answers/5196497701/ 是我必须做的,而不是更改身份验证类型。 (6认同)