Five supabase-js mistakes that are easy to ship, and how to catch them before you do #52006
guptaaman678
started this conversation in
Show and tell
Replies: 1 comment
|
Good list. Point 3 is wider than reads, and it trips people up because the fix for one operation depends on a policy for another:
A quick way to see silent zero-row updates: const { data, error } = await supabase
.from('todos').update({ done: true }).eq('id', id).select('id')
if (!error && data.length === 0) console.warn('0 rows matched (RLS or filter)')And when adding the missing SELECT policy, scope it, e.g. The behavior is in the CREATE POLICY docs, under "Policies Applied by Command Type": https://www.postgresql.org/docs/current/sql-createpolicy.html |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Unofficial and community-written: I'm not from Supabase, and the tool at the end is my own.
When a Supabase feature "just stops working" and there's no error anywhere, it's often one of the first four below. Each of them returns normally, so nothing in your logs or tests tells you. The fifth does fail with 42501, but only once the call actually runs.
1. A voided query is never sent. supabase-js query builders are lazy, so nothing goes out until something calls
.then().awaitdoes that.voiddoesn't.Fix:
awaitit, or chain.then().2. A subscription to a table that isn't published. If the table isn't in the
supabase_realtimepublication, the channel reachesSUBSCRIBEDand then never receives apostgres_changesevent.3. RLS on, no select policy. A read comes back as
data: []witherror: null. An update or delete changes nothing, again with no error. (Inserts fail loudly with 42501.) The fix is a policy for the role your client uses.4.
.subscribe()with no status callback.CHANNEL_ERRORandTIMED_OUTgo nowhere. Pass(status, err) => { ... }and handle them.5. No grant for the role. From 2026-10-30, new tables in
publicstop getting automatic grants foranon,authenticatedandservice_role. A call on a table the role has no grant for fails with 42501, and a Realtime subscription on it connects and receives nothing. Put thegrantin the same migration that creates the table. (Tools that replay your migrations only see this change once your project records it: the opt-in migration, or for grants-lint and the plugin below, thesincesetting ingrants-lint.config.json.)You can spot the first and the fourth from the code alone. The other three need the code and your migrations together, because
supabase.from('orders').select()looks fine until you know what the migrations say aboutorders.That's why I wrote an ESLint plugin that replays
supabase/migrationsinto a model of the database and checks each client call against it, right in your editor: eslint-plugin-supabase. It doesn't open a network connection or read your.envfile. If it can't trace a client, it skips the call. If it can trace the client but can't classify its key (createClient(url, config.key)), it treats it like a publishable-key client by default, andunknownKey: "skip"skips those too. If it flags something that isn't a bug, I'd really like an issue on the repo.Not affiliated with or endorsed by Supabase.
All reactions