Search

PythonReactSEOPDF
GitHub Skill

supabase-rls

Supabase RLS 政策規範。Use when creating or modifying RLS policies (CREATE POLICY, ALTER POLICY), setting up Row Level Security, or working with database access control. Always use this skill for RLS design, policy templates, and role-based access patterns.

Charles5277☆ 38 Repository stars2 Repository forks

Installation

Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.

View source ↗Guides

Skill instructions

Supabase RLS 政策規範

service_role 繞過規則已定義在 CLAUDE.md。本 skill 提供完整 RLS 實作指引。

核心原則

使用 Helper 函式

建議建立 helper 函式取代直接查表:

-- ✅ 使用 helper
your_schema.current_user_role()
your_schema.current_user_id()

-- ❌ 直接查表(效能差)
SELECT role FROM your_schema.user_roles WHERE id = auth.uid()
RLS 開啟原則
ALTER TABLE your_schema.new_table ENABLE ROW LEVEL SECURITY;
ALTER TABLE your_schema.new_table FORCE ROW LEVEL SECURITY;

常見問題

症狀 原因 解法
Toast 成功但資料沒變 缺少 service_role 繞過 加上 (SELECT auth.role()) = 'service_role'
查詢回傳空陣列 RLS 未開放讀取 檢查 SELECT policy

參考資料

檔案 內容
references/templates.md Policy 模板 + 角色階層

檢查清單

  • 包含 (SELECT auth.role()) = 'service_role' 繞過
  • 使用 helper 函式而非直接查表
  • INSERT/UPDATE/DELETE 都有對應 policy
  • supabase db lint --level warning 無警告

Examples

Read the usage examples in the source repository.

View source ↗

Source history

Indexed on
2026-03-11
Index updated
2026-03-11
Branch
main

Index and sync dates describe this directory. View the source repository for code history.

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!