はじめに
取得した位置情報をsupabaseのテーブルへ保存しようとした際、以下のようなエラーが表示されました。
こちらの解決方法について躓いたため備忘録をふくm記事にします。
https://hogehoeehoge.supabase.co/rest/v1/post_locations 403 (Forbidden)
アクセス権限がないようです。
既に以下のようにgisスキーマを作成しPostGIS拡張機能を許可していましたが、うまく挙動していないようでした。
CREATE SCHEMA gis;
create extension postgis with schema gis;
解決方法
作成したgisスキーマを削除し、extensionsスキーマにPostGIS拡張機能を許可
強制削除
DROP EXTENSION postgis CASCADE;
extensionsスキーマにPostGIS拡張機能を許可
CREATE EXTENSION postgis WITH SCHEMA extensions;
権限付与
GRANT USAGE ON SCHEMA extensions TO anon, authenticated, service_role;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA extensions TO anon, authenticated, service_role;
テーブル再作成
create table if not exists public.post_locations (
post_id int not null references posts(id) on delete cascade,
location geography(POINT) not null,
PRIMARY KEY(post_id)
);
Database反映
npx supabase gen types typescript --project-id "プロジェクトID" --schema public > utils/supabase-database.ts
参考
おわりに
とりあえず今回はこちらの方法で解決することができました。
データベースの扱いももっと習熟したいと思いました。