简体   繁体   English

当数据在相关表中时,Next JS 中的 supbase 返回一个空数组

[英]supabase in Next JS returning an empty array when data is in relevant tables

It seems I am always returning an empty array when trying to pull data from my tables.尝试从表中提取数据时,我似乎总是返回一个空数组。 This is how I am doing it, after following the docs and several tutorials.在遵循文档和几个教程之后,这就是我的做法。

const [tableData, setTableData] = useState([]);

  async function getTableData() {
    let { data, error } = await supabase
      .from('SignalJourneyAudienceConstraints')
      .select('*');

    setTableData(data);
    console.log(tableData);
  }

  useEffect(() => {
    getTableData();
  }, []);

I have data in the table as so.我在表中有数据。

在此处输入图像描述

The only thing I can think of is the naming of the table??我唯一能想到的就是表的命名??

I have also tried the following我也试过以下

let { data: SignalJourneyAudienceConstraints, error } = await supabase
  .from('SignalJourneyAudienceConstraints')
  .select('*')

But getting an error ReferenceError: data is not defined and in VSC I'm getting All destructured elements are unused.ts(6198) with the above.但是得到一个错误ReferenceError: data is not defined并且在 VSC 中我得到All destructured elements are unused.ts(6198)与上述。

I have always seen tutorials just use data though.我一直看到教程只是使用data

我不得不在我的桌子上关闭 RLS。

you should disable RLS (not secure) or define policy for your table .您应该禁用 RLS(不安全)或为您的表定义策略。 (every table in your project has its own policies and should create ruls seprately) (您项目中的每个表都有自己的策略,应该单独创建规则)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM