Fixes › Database / Supabase RLS
Supabase update says saved but the change is gone after refresh
Published
The error
update() returns no error but nothing changes / { data: [], error: null } / 'Saved!' toast, then the old value is back after a page refreshWhy it happens
With Row Level Security on, an UPDATE only touches rows the current user is allowed to see and allowed to change. If no row passes the policies, Postgres simply updates 0 rows, and Supabase returns success with no error, so the AI-generated code shows 'Saved' even though nothing was written. The usual reasons: there is no UPDATE policy on the table at all; there is an UPDATE policy but no SELECT policy (Supabase's docs note an UPDATE also needs a matching SELECT policy, because Postgres has to read the row before it can update it); the policy checks a column such as user_id that the row doesn't actually have set for this user; the user isn't signed in, so the request runs as anon; or the .eq() filter targets the wrong id. Optimistic UI updates in the frontend make it look saved until the page reloads.
How to fix it
- Prove it: chain .select() onto the update, e.g. supabase.from('profiles').update({name}).eq('id', id).select(). If data comes back as an empty array, 0 rows were updated.
- In Supabase Dashboard → Authentication → Policies (or Table Editor → the table → RLS policies), check the table has both a SELECT policy and an UPDATE policy that cover this user's rows.
- Write the UPDATE policy with both clauses, e.g. using (auth.uid() = user_id) with check (auth.uid() = user_id), and make sure a SELECT policy with the same ownership rule exists.
- Check the row really belongs to the user: look at it in the Table Editor and confirm user_id (or owner_id) matches the signed-in user's id, and that rows created earlier weren't saved with a null owner.
- Confirm the request is authenticated: log supabase.auth.getUser() just before the update. If it's null, the update runs as anon and no authenticated policy applies.
- In the frontend, only show 'Saved' after the update returns at least one row, and show an error otherwise, so silent failures can't hide again. Don't fix it by disabling RLS or using the service role key in the browser.
Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)
In my app, saving changes to <TABLE> shows a success message but the change is gone after refresh. I think Supabase RLS is making the update match 0 rows. Don't disable RLS and don't use the service role key in the frontend. Add .select() to the update call and treat an empty result as a failure with a clear error message. Then check the RLS policies on <TABLE>: make sure there is a SELECT policy and an UPDATE policy (with both USING and WITH CHECK) that allow the signed-in user to read and update their own rows via auth.uid() = user_id. Give me the exact SQL, and tell me how to check that existing rows have user_id set to the right user.
Error codes this fixes
FAQ
Why is there no error?
Postgres treats 'no rows matched' as a successful update of 0 rows. RLS filters out rows you can't see before the update runs, so there's nothing to report as an error.
I added an UPDATE policy and it still doesn't save.
Add a SELECT policy for the same rows too. Without it, the update can't see the row it's meant to change.
Inserts work, so why not updates?
Insert, select, update and delete each need their own policy. An INSERT policy says nothing about updates.
Is the service role key a fix?
Only on a trusted server. In the browser it bypasses all security, so anyone could edit anyone's data. See the leaked service role key fix.
Sources
Based on the official documentation:
Related fixes
- Supabase only returns 1,000 rows (max rows limit)
- Any user can make themselves admin or Pro: Supabase RLS lets users update their own role, plan or is_admin column
- Replit rollback did not bring my data back: how to restore the development or production database
- Supabase .single() error PGRST116: JSON object requested, multiple (or no) rows returned
Get one new fix a week
Free newsletter: the newest breakages in Lovable, Bolt, Cursor, Replit and v0 apps, with paste-in fixes.
We only use your email to send the newsletter. Unsubscribe any time. See privacy.