模型“更新”时出现订阅 UnauthorizedException 警告。如何关闭订阅?

问题描述 投票:0回答:2

我最近更新了我的 AWS Amplify 前端 (NextJS),以删除对我在 schema.graphql 文件中创建的“Card”对象的任何订阅。由于某种原因,我仍然在我的开发工具控制台中收到警告,告诉我在“卡”模型上执行“更新”时存在有关授权的订阅问题。我最好的猜测是,数据存储仍在后台执行某种订阅功能,但我找不到任何信息来解释发生了什么或如何对警告采取行动。谁能帮忙解释一下这个吗?

我的 schema.graphql 显示订阅应该在卡上关闭:

type Card
  @model(subscriptions: null) # Removed subscriptions
{...}

我曾经在我的 JavaScript 中设置了订阅,但我也删除了它们,例如:

// I have deleted all code relating to subscriptions, such as the following:
  const subscription = DataStore.observe(Card).subscribe(() => fetchCards());
  return () => subscription.unsubscribe();

我在开发工具控制台中收到此警告消息:

DataStore - subscriptionError Connection failed: {
  "errors":[{
    "errorType":"UnauthorizedException",
    "message":"Permission denied"
   }
]}

随后出现此警告:

react_devtools_backend.js:4026 [WARN] 
39:46.202 DataStore 
{
  recoverySuggestion: 'Ensure app code is up to date, auth directives
  exist and are correct on each model, 
  and that server-side data has not been invalidated by a schema
  change. If the problem persists, search for or create an issue:
  https://github.com/aws-amplify/amplify-js/issues', 
  localModel: null, 
  message: 'Connection failed: 
    {
       "errors": [
         {
           "errorType":"UnauthorizedException", 
           "message":"Permission denied"
          }
        ]
}', 
  model: 'Card', operation: 'Update', 
…}
reactjs next.js aws-amplify aws-appsync aws-datastore
2个回答
1
投票

在学习介绍性 AWS Amplify 教程时,我遇到了类似的错误消息。

我的解决方案是将身份验证配置添加到文件index.js中:

import { AuthModeStrategyType } from 'aws-amplify'

Amplify.configure({
   ...config,
   DataStore: {
     authModeStrategyType: AuthModeStrategyType.MULTI_AUTH
   }
 })

此更改后,数据更新和授权规则均按预期运行,没有浏览器控制台错误。

有关更多信息,请参阅 AWS lib 文档的这一部分。


0
投票

上面的答案,由 James-h 提供,直到今天才对我有用。就在现在。

© www.soinside.com 2019 - 2024. All rights reserved.