Your Lovable / Bolt app: Supabase login, data or n8n-webhook bug, fixed and tested

Three bugs that show up again and again in AI-built apps. For each one: what the founder sees, the root cause, a before/after fix, and an automated test that fails on the broken code and passes on the fix.

Verified result

Same 7 automated tests run against both versions. Run on 02 Dec 2026 (Europe/Vienna), Node v24.22.1, local Postgres via PGlite 0.6.1 (Postgres compiled to WASM). No hosted services involved.

1 / 7
passing on the broken (BEFORE) code. The one pass is a security guard test.
7 / 7
passing on the fixed (AFTER) code.
TestBeforeAfterError on the broken code
Bug 1: user sees their own todosFAILPASSexpected Alice's 2 todos, got 0
Bug 1: user creates a todo and reads it backFAILPASS42501: new row violates row-level security policy for table "todos"
Bug 1 guard: no other users' rows, no spoofed inserts, anon sees nothingPASSPASSfix must not open the table
Bug 2a: filter matches the stored status valueFAILPASSexpected 2 active sample projects, got 0
Bug 2b: dashboard loads after the session is restoredFAILPASSexpected 2 projects after login, got 0
Bug 3a: StrictMode plus double click sends exactly 1 webhook requestFAILPASSn8n received 4 requests
Bug 3b: a 504 after processing is retried without a duplicateFAILPASSwebhook failed (no retry, no idempotency key)

Test 2b fails on the broken code for two reasons at once (the wrong filter from 2a and the session timing).

FIX 1

Supabase RLS policy hides the user's own rows

What you see: "I'm logged in, but my list is empty. Saving a new item fails with new row violates row-level security policy (42501)." Everything works in the Supabase table editor, because the service role bypasses RLS.

Root cause: the policies compare auth.uid() with the row's primary key id instead of the owner column user_id, for both USING (read) and WITH CHECK (insert).

Before
create policy "Users can view their own todos"
  on public.todos
  for select to authenticated
  using (auth.uid() = id);

create policy "Users can create todos"
  on public.todos
  for insert to authenticated
  with check (auth.uid() = id);
After
create policy "Users can view their own todos"
  on public.todos
  for select to authenticated
  using ((select auth.uid()) = user_id);

create policy "Users can create their own todos"
  on public.todos
  for insert to authenticated
  with check ((select auth.uid()) = user_id);

(select auth.uid()) lets Postgres evaluate the function once per statement instead of once per row. A guard test confirms the fix did not open the table: other users' rows stay invisible, spoofed inserts are rejected, and anonymous users see nothing.

FIX 2

Query returns empty although the data exists

What you see: "The dashboard says 'No projects'. Sometimes they appear after a refresh."

Two typical root causes:

Before
// 2a: "Active" never matches "active"
const { data } = await client
  .from('projects')
  .select('id,name,status')
  .eq('status', 'Active');

// 2b: runs once on mount, before the
// session exists
useEffect(() => { load() }, [])
After
// 2a: one typed source of truth that
// matches the DB check constraint
type ProjectStatus = 'active' | 'archived';
.eq('status', 'active' as ProjectStatus)

// 2b: wait for the session, reload when
// the auth state changes
useEffect(() => {
  if (session) load()
}, [session?.user.id])

In the repo the React hook is reproduced by a small lifecycle stand-in; the logic under test is the same: never query user data until a session exists, and reload on onAuthStateChange.

FIX 3

Form submit fires the n8n webhook twice

What you see: "Every contact form submission creates two rows in my CRM, or two emails from n8n."

Root cause: the POST is sent from a useEffect(..., []) in a component that mounts after submit. React StrictMode (dev) mounts components twice, so the effect runs twice. The button also stays clickable, so a double click doubles it again: the test measured 4 requests for one double click. There is no idempotency key, so the receiver cannot tell duplicates apart.

Before
// rendered after submit; effect runs
// twice in StrictMode
function SubmitSender({ values }) {
  useEffect(() => {
    fetch(WEBHOOK_URL, {
      method: 'POST',
      body: JSON.stringify(values),
    })
  }, [])
  return null
}
// button never disabled, no retry,
// no idempotency key
After
// send from the submit handler, once
async function onSubmit(values) {
  if (submitting.current) return
  submitting.current = true
  key.current ??= crypto.randomUUID()
  try {
    for (let i = 1; ; i++) {
      const res = await fetch(WEBHOOK_URL, {
        method: 'POST',
        headers: { 'Idempotency-Key': key.current },
        body: JSON.stringify({
          ...values,
          idempotency_key: key.current,
        }),
      })
      if (res.ok) { key.current = null; return }
      if (i >= 3 || res.status < 500) throw new Error('failed')
    }
  } finally { submitting.current = false }
}
// <button disabled={submitting}>

n8n side (recommended in addition): right after the Webhook node, store the key with a unique constraint and stop if it already exists:

Dedup step (Postgres / Supabase node)
insert into webhook_events (idempotency_key, payload)
values ($1, $2)
on conflict (idempotency_key) do nothing
returning idempotency_key;
-- IF node: no row returned -> duplicate -> stop

This SQL runs on PGlite in the test suite via a mock receiver. It was not tested against a running n8n instance.

Limits of this demo

How I would work on your app

  1. Reproduce the bug with a test user or anonymized data.
  2. Fix the cause, not the symptom, and keep the fix as small as the bug allows.
  3. Hand over the fix with a test and a short note on what changed and why.

I do not need your passwords or your service-role key. A GitHub invite and a Supabase project invite (or a dedicated test user) are enough.