获取未经授权的错误-AWS GraphQl查询

发布于 2025-02-03 02:03:44 字数 817 浏览 3 评论 0原文

我正在尝试从AWS GraphQl API获取一些数据:

这是模型:

type List @model @auth(rules: [{ allow: public, operations: [read] }]) {
  id: ID!
  title: String!
  sprints: [Sprint] @hasMany(indexName: "byList", fields: ["id"])
  organizationID: ID! @index(name: "byOrganization")
}

这就是我获取它的方式:

 async function fetchLists() {
    try {
      const listData = await API.graphql({
        query: listLists,
        authMode: "AMAZON_COGNITO_USER_POOLS",
      });
      const lists = listData.data.listLists.items;
      setLists(lists);
      console.log({ lists });
    } catch (err) {
      console.log({ err });
    }
  }

  useEffect(() => {
    (async () => {
      await fetchLists();
    })();
  }, []);

我什至在这里不需要任何auth规则,但它也不起作用。

有一个授权标题,但仍会遇到错误。

I'm trying to get some data from the AWS GraphQL API:

Here is the model:

type List @model @auth(rules: [{ allow: public, operations: [read] }]) {
  id: ID!
  title: String!
  sprints: [Sprint] @hasMany(indexName: "byList", fields: ["id"])
  organizationID: ID! @index(name: "byOrganization")
}

And this is how I fetch it:

 async function fetchLists() {
    try {
      const listData = await API.graphql({
        query: listLists,
        authMode: "AMAZON_COGNITO_USER_POOLS",
      });
      const lists = listData.data.listLists.items;
      setLists(lists);
      console.log({ lists });
    } catch (err) {
      console.log({ err });
    }
  }

  useEffect(() => {
    (async () => {
      await fetchLists();
    })();
  }, []);

I don't even need any auth rules here, but it doesn't work either.

There is an authorization header, but still getting the error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

近箐 2025-02-10 02:03:44

尝试将模式更改为此,以允许apikey如果您有多种授权类型。并删除authmode:“ Amazon_Cognito_user_pools”从您的代码中。

type List 
  @model 
  @auth(
    rules: [
      { allow: public, operations: [read], provider: apiKey }
    ]
  ) {
  ...
}

Try changing your schema to this to allow apiKey authorization If you have multiple authorization types. And remove authMode: "AMAZON_COGNITO_USER_POOLS" from your code.

type List 
  @model 
  @auth(
    rules: [
      { allow: public, operations: [read], provider: apiKey }
    ]
  ) {
  ...
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文