reactjs 订阅UnauthorizedException在模型“更新”时发出警告,如何关闭订阅?

avkwfej4  于 2022-12-22  发布在  React
关注(0)|答案(1)|浏览(113)

我最近更新了AWS Amplify前端(NextJS)删除我在schema.graphql文件中创建的对“Card”对象的订阅。由于某种原因,我仍然在开发工具控制台中收到警告,告诉我在“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', 
…}
u5i3ibmn

u5i3ibmn1#

我在遵循introductory AWS Amplify tutorial时也有类似的错误消息。
我的解决方案是将身份验证配置添加到文件index.js中:

import { AuthModeStrategyType } from 'aws-amplify'

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

此更改后,数据更新和授权规则均按预期工作,没有浏览器控制台错误。
有关详细信息,请参阅AWS库文档的此部分。

相关问题