Supabase update returns no error but nothing changes

Updated · by Zane

Why a blocked update looks like a success

Row Level Security (RLS) is a set of rules attached to a table. Most people expect a rule to stop a request with an error. That is not how it behaves for updates and deletes. The rules decide which rows you are allowed to see, and the statement only runs on those rows. If the allowed set is empty, the statement runs on nothing. It succeeds, and it changes 0 rows.

So your app sees no error, your function logs nothing odd, and the data stays the same. Inserts behave differently. A blocked insert fails with the Postgres message new row violates row-level security policy for table "profiles", with your table name in place of profiles.

I hit this in a demo project where a payment webhook was meant to set a user's plan. The payment went through and the plan never changed. The full story is in the guide on Stripe payments that leave the user on Free. This guide covers the database side on its own.

With row level security, an update runs only on the rows the caller may see. If that set is empty the statement succeeds and changes 0 rows, so the app gets no error and only a row count check shows it. A blocked insert, by contrast, fails with an error.

Step 1: confirm that 0 rows were changed

Add .select() after the update. It makes Supabase return the rows that were changed. Then check the length of the array.

Detect an update that changed nothing
const { data, error } = await supabase
  .from("profiles")
  .update({ plan: "pro" })
  .eq("id", userId)
  .select("id");

if (error) {
  console.error("update error:", error.message);
} else if (!data || data.length === 0) {
  // No error, but nothing was changed
  console.error(`update affected 0 rows for user ${userId}`);
}

In my demo project the webhook used the public anon key, and RLS blocked the write. The call returned error as null and data as an empty array. This is the log line that showed it:

Function log
[webhook] profiles update affected 0 rows for user <id> (blocked by RLS or missing row)

Without the row count check, that function would have returned 200 and looked healthy. Do the check in any code that matters, and treat an empty result as a failure.

To look at the policies, open the Supabase Dashboard, then Authentication, then Policies. In the Table Editor you can also see an RLS marker next to each table name.

The three usual causes

1. No UPDATE policy, or one that does not match the user

With RLS on and no UPDATE policy, nobody using the public key can update anything. Sometimes a policy exists but its condition never matches. Two examples I would check:

  • The policy says auth.uid() = user_id, but the column that holds the user id is really called id.
  • The condition is right, but the user_id on that particular row is empty, so no signed-in user matches it.

2. The caller is not who you think it is

Server code, such as an Edge Function or a webhook, is easy to write with the anon key. Nobody is signed in on that path, so auth.uid() is null and no policy that depends on it can match. The write is filtered out.

3. The filter itself matches no row

This one has nothing to do with RLS. If .eq("id", userId) is given the wrong id, or a value of a different type, no row matches and 0 rows change. Print the id you pass and compare it with the table.

Two details of UPDATE policies

An UPDATE policy has two parts. USING decides which existing rows you may change. WITH CHECK decides whether the new version of the row is allowed. Writing only one of them is a common source of confusing results.

Also, .select() reads the row back, and reading needs permission. If you have no SELECT policy for that row, the returned array can be empty even though the update ran. If that happens, add the SELECT policy too.

Fix A: the user edits their own data

If the field is something the user should change, such as a display name, add a policy that limits the update to their own row. This example uses a profiles table with an id column that matches the user id:

SQL
-- Let a signed-in user update only their own row
create policy "profiles_update_own" on public.profiles
  for update to authenticated
  using (auth.uid() = id)
  with check (auth.uid() = id);

-- .select() also needs permission to read the row back
create policy "profiles_select_own" on public.profiles
  for select to authenticated
  using (auth.uid() = id);

Run it in the Supabase SQL editor, then repeat the update from the app while signed in.

Fix B: the server changes a protected field

Some columns must not be editable by users at all. The paid plan is the clearest example. For those, do not write a policy that lets users update them. Do the write on the server with the service role key. In newer projects this key is called the secret key. It bypasses RLS entirely, so it belongs only in server environment variables.

Server-side client
// Server only: the service role key bypasses RLS
const supabase = createClient(
  Deno.env.get("SUPABASE_URL")!,
  Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!,
);

Keep the row count check from step 1 on top of it. If you want to be sure your other tables are in good shape, the guide Is your Supabase data public? takes about two minutes.

What not to do

  • Do not switch RLS off to get past this. Anyone with your public key could then read and change every row.
  • Do not add a policy with using (true) just to see it work. That is the same as having no protection on the table, and these quick fixes tend to stay in place.

Test the fix

  1. Run the update again with .select() and confirm the array has one row.
  2. Open the table in the Dashboard and confirm the value changed.
  3. As a different signed-in user, try to update the first user's row. It should still change 0 rows.
  4. Refresh the app and confirm the screen shows the new value.

FAQ

Why is there no error?

Row Level Security works as a filter, not as an alarm. An update only touches the rows your policies let you see. If that set is empty, the statement succeeds and changes 0 rows. Inserts are different: a blocked insert does raise an error.

Should the user be able to update their own plan?

No. If a user can write to the plan column, anyone can upgrade themselves for free by calling the API directly. Let users edit harmless fields like their name, and change the plan only from your server after a verified payment.

Does the service role key go in my frontend?

Never. It skips every RLS policy, so anyone who finds it in your page code can read and change all your data. Keep it in server environment variables only.

Checklist

Still stuck?

Send me the app link and what's broken. The first look is free and you get a fixed quote before I touch anything.

Related guides