Commit Graph
6 Commits
Author SHA1 Message Date
JerryandNik Richers 3389756a4c fix(docs): correct the JWT team policy example (#53777)
## Problem

Fixes #53776

We hit this while adding team-scoped RLS to a project from the guide.
Creating the policy fails with:

```text
ERROR:  operator does not exist: uuid = jsonb
```

The example uses `team_id in (select auth.jwt() -> 'app_metadata' ->
'teams')`. `->` returns a single `jsonb` value, so `in (select ...)`
compares `team_id` to that jsonb value.

## Solution

Expand the claim with `jsonb_array_elements_text`, cast each team ID to
`uuid`, and compare it with `= any (array(...))`:

```sql
using (
  team_id = any (
    array(
      select (jsonb_array_elements_text((select auth.jwt()) -> 'app_metadata' -> 'teams'))::uuid
    )
  )
);
```

`app_metadata.teams` must be an array of UUID strings, for example
`{"app_metadata": {"teams": ["22222222-2222-2222-2222-222222222222"]}}`.
Objects such as `[{"id": "..."}]` fail the cast.

Comparing UUID to UUID means uppercase values in the claim still match
and Postgres can use an index on `team_id`. The guide and the AI prompt
in `examples/prompts/database-rls-policies.md` both document the
expected claim shape and that `team_id` is a `uuid`; for other ID types,
cast the array element to that type instead.

## Review instructions

1. Open the `auth.jwt()` section of the [RLS
guide](https://supabase.com/docs/guides/database/postgres/row-level-security#auth-jwt).
2. Run the updated `create policy` statement against Postgres. It should
create without error.
3. Check that a user whose `app_metadata.teams` is an array of UUID
strings containing the row's `team_id` sees the row, including when the
claim uses an uppercase UUID, and that a user without it does not.

I checked these steps on Postgres 14.

## Checklist

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)

I used AI to help debug this. The fix and this pull request are mine; I
reviewed the change before opening it.

---------

Co-authored-by: Nik Richers <nrichers@gmail.com>
2026-11-24 22:20:38 +00:00
Steven Eubank 82f79e5af6 Fix logic conflicts (#40362)
When applying these rules to my personal project. My cursor bug bot detected logical gaps in these 2 prompts.
2026-01-27 02:42:41 +00:00
Tyler e3b03513e9 examples: Updates example rules to match the latest format of Cursor rules and add declarative schema example (#34992)
* remove glob from all examples

* Add declarative schema instructions

* run prettier

* update file extension for declarative-database-schema rule

* update the example prompts in the examples folder
2025-04-16 01:02:10 +09:00
TylerandCharis Lam b3cbbc7353 docs: Fix AI prompts page title and menu item title. (#33341)
* remove displaying heading for the AI prompts

* remove the prompt note for test

* revert the change for not displaying the heading for the menu

* Add back the title for each prompt

* allow putting frontmatter before heading

---------

Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
2025-02-06 09:14:01 +09:00
Tyler 806a8227b9 docs: Update the prompt examples to make it more Cursor friendly (#33315)
* Update the instruction to add to project

* bringing Cursor at the front, because that is the most popular one of all

* Add sample description and globs for all sample prompt within the docs

* remove the cursor rule I created by mistake

* fix typo
2025-02-05 10:16:25 +09:00
Greg Richardson da52ba3245 More AI prompts (#31252)
* feat: more database prompts

* fix: title casing
2024-12-19 12:19:19 -07:00