0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Supabaseで全然GETができないと思ったらRLSの設定問題だった

0
Last updated at Posted at 2024-05-23

起きたこと

vue3とSupabaseで新しいプロジェクトを生成して、早速GETをしてみた。

<script setup lang="ts">
import { supabase } from '@/utils/supabase'

const getCategories = async (): Promise<void> => {
  let { data } = await supabase.from('category').select('*')
  categories.value = data;
}

onMounted(() => {
  getCategories();
});
</script>

ドキュメント通りのコードだけど、空の配列しか返っておらず...
空の配列が返ってきてるってことは接続はできているはず。

原因

RLS(Row Level Security)の設定がないことが原因だった。
前作ったプロジェクトでは何も知らずに設定してたぽい。

解決方法

該当テーブルのページに移動、RLS disabledボタンをクリック
スクリーンショット 2024-05-23 22.58.50.png
以下のように進む

スクリーンショット 2024-05-23 22.59.39.png
スクリーンショット 2024-05-23 23.00.07.png
するとAuthenticationのページに移動する。
早速policyを作りましょう。

スクリーンショット 2024-05-23 23.00.49.png

エンドポイント別に揃っている。今回はGETが目的なのでSELECTだけを選択、保存。

スクリーンショット 2024-05-23 23.01.21.png

結果

問題なくGETできた!

初歩の初歩だが、知らないと時間かかる、、

スクリーンショット 2024-05-23 23.02.14.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?