← All posts
SupabaseSecurityFix notes

Your app was built with AI and works in the demo. Here’s what breaks in production, and how to fix it.

Apps built with Lovable, Bolt, Cursor or v0 on Supabase usually fail in the same places: database rules, secrets in the browser, payments trusted on the client, and no plan for things going wrong. Here is the checklist I use, and the fixes from apps I shipped.

Reda BellasseryReda Bellassery· ·8 min read
Three screens of Belka Tech English, a React Native app on Supabase: the home dashboard, the learner’s courses and the profile
Three screens of Belka Tech English, a React Native app on Supabase: the home dashboard, the learner’s courses and the profile
Three screens of Belka Tech English, a React Native app on Supabase: the home dashboard, the learner’s courses and the profile

Key takeaways

  • AI app builders produce screens that work when every user behaves. Production problems live where the demo never looks: database rules, server code and failure cases.
  • On Supabase the browser talks straight to the database with a public key, so row-level security is the only thing between a user and every other user’s data.
  • Anything that decides money or access, such as payments, plan limits and paid features, has to be decided by the server or the database, never by the app.
  • In Belka, the fix for paid levels anyone could grant themselves was not better app code. It was deleting the app’s permission to write access at all.
  • Most AI-built apps don’t need a rebuild. The screens are usually fine. The rules underneath them need an audit and a few targeted fixes.

You built your app in a few weekends with Lovable, Bolt, Cursor or v0. It has sign-up, a dashboard, a pricing page and a Supabase database behind it. In the demo, everything works.

Then real people arrive. A payment goes through but the feature stays locked. A user somehow has the premium plan without a payment on record. The app freezes when the network drops on a train. And a developer friend opens the browser console and goes quiet for a minute.

The AI tool did what you asked. It built screens that work when everyone behaves. Production is the place where people, networks and payment providers don’t.

This post is for founders and small companies with an app built mostly by AI tools, on Supabase, that now has to carry real users and real money.

Why does an AI-built app work in the demo and break in production?

Because a demo only tests the path you can see. AI builders are very good at that path. The problems sit in parts you never click: database rules, server code, and what happens when a request arrives twice, late or not at all.

Supabase makes this sharper. In a typical Lovable or Bolt app, the browser talks straight to the database with a key that is public by design. There is often no server of your own in between. So the rules inside the database are the only protection you have.

The most important of those rules is row-level security (RLS), which is the database checking, for every row, who may read or change it. If it is off, or written too loosely, anyone with your public key can read or edit any table.

A production-readiness audit is a review of exactly those hidden parts: who can read and write each table, which secrets reach the browser, where money is checked, and what happens when things go wrong. That is the work this post is about.

I’m not against AI tools. I use them every day, and I run part of my own business with an AI team. But a tool that writes the screen first tends to put the rules in the screen too.

I made the most expensive of these mistakes myself

This isn’t only an AI-builder problem. I built Belka Tech English solo, a React Native app on Supabase that sells English levels to Algerian workers in dinars. In its first version, the app itself wrote the level unlocks.

The table that stored who owns which level, user_level_access, had a policy allowing the app to insert rows. That meant any signed-up user could insert rows and grant themselves every paid level. A second hole let a promo code with no level attached unlock anything.

The level ladder and the paywall in Belka. The padlock is cosmetic. What gates the content is a row in user_level_access that the app has no permission to write.
The level ladder and the paywall in Belka. The padlock is cosmetic. What gates the content is a row in user_level_access that the app has no permission to write.
The level ladder and the paywall in Belka. The padlock is cosmetic. What gates the content is a row in user_level_access that the app has no permission to write.

The fix was not cleverer app code. I removed the app’s write path entirely. Grants now come only from a payment webhook the server verifies, or from a database function that checks and redeems a promo code in one step. Codes without a level are rejected. I wrote up the whole fix in a separate post about paid features unlocked for free, and it’s in the Belka case study.

If the client can write the entitlement, the entitlement is not real.

Security: who can read and write what?

Start here, because these holes leak data and money without anyone noticing. These are the checks I run first on any Supabase app:

  1. RLS on every table. Supabase’s Security Advisor in the dashboard flags tables with RLS turned off. Each one is a table anyone can read and write with your public key.
  2. Policies that actually filter. A policy that says “any signed-in user may read” is barely better than none. Each user should only see their own rows, for example auth.uid() = user_id, which is how Belka restricts entitlements.
  3. No secrets in the browser. The anon key is fine in the frontend. The service_role key, OpenAI keys and Stripe secret keys are not. In Vite apps anything prefixed VITE_ ends up in the bundle, and in Next.js the same goes for NEXT_PUBLIC_.
  4. Users can’t change their own role or plan. A role, is_admin or plan column in a profile row the user can update is a self-service promotion. In Biggo, a car marketplace I built for a client of my agency, the role is clamped to safe values at sign-up and a trigger blocks self-role changes.

Money and limits: what must the server decide?

Anything that decides access or costs money must be decided by the server or the database. The app can display the answer. It can’t be the one giving it.

  • Payments. A “thank you” page that unlocks the purchase can be opened by anyone who knows the URL. Access should come from a payment-provider webhook whose signature the server checks. In Belka that is an HMAC-verified checkout.paid event. If customers pay and access doesn’t appear, that’s the other side of the same design, covered in payment received, access missing.
  • Plan limits. “Five listings on the basic plan” enforced only by hiding a button can be bypassed with one API call. In Biggo the caps on listings, photos, ads and monthly edits live in database triggers, so they hold even against raw API calls with a stolen token. More on that in plans, roles and limits in a marketplace.
  • AI usage. If your app calls an AI model, every call costs you money. In Spirex, my AI trading analysis app, usage is metered on the server and deducted before the model call, so an expensive feature can’t outrun what the account paid for. See when an AI feature costs too much.

What happens when things go wrong?

AI-generated code usually handles success and shows a red toast for everything else. Real failures are more specific, and each needs a decision:

  • Double taps and retries. In Belka, promo redemption happens in a single database transaction, so two taps can’t claim the same code twice. In Al Burhan, a cash-control platform for a four-branch retail group, every financial write carries an idempotency key, so a retry after a dropped connection can’t double-count a sale.
  • Things that arrive late. In Belka the learner pays in an external browser and the app can come back before, during or after the payment is confirmed. Three separate return paths all lead to one verification routine that waits for the server’s grant.
  • Lost progress. Belka saves lesson progress to Postgres keyed on user, field, level and lesson, so it survives a reinstall and a repeated save doesn’t create duplicates.
Left: the unlock screen, with promo code and Dahabia card. Neither path lets the phone grant itself access. Right: lessons unlock in order, and progress is saved on the server.
Left: the unlock screen, with promo code and Dahabia card. Neither path lets the phone grant itself access. Right: lessons unlock in order, and progress is saved on the server.
Left: the unlock screen, with promo code and Dahabia card. Neither path lets the phone grant itself access. Right: lessons unlock in order, and progress is saved on the server.

Data model and tests: the parts nobody asks for

The data model is where AI-built apps age worst. Two rules save the most pain. Store money as integers, as Al Burhan does with centimes, never as floats. And keep financial history append-only, so a correction is a new entry instead of an edited row.

Tests are the other gap. Most AI-built apps have none, and I won’t pretend all of mine are better. Belka’s test suite is a single smoke test, and its case study lists that as the first debt I’d pay. The tests worth writing first are the ones around money and access: can a normal user write to the access table, and does a fake webhook get rejected?

Biggo taught me why. After I tightened a database permission for hygiene, the public site showed zero cars, because the listing rules depended on a function anonymous visitors could no longer run. It was fixed with a targeted migration, but the lesson stuck: security changes need the same testing as features.

The audit checklist you can run today

You don’t need to read code for most of this. Open your Supabase dashboard, open your app with the browser’s developer tools, and go down the list.

CheckHow to lookWhat good looks like
RLS is onSupabase Security AdvisorNo table without RLS in the public schema
Users only see their own dataSign in as two test usersUser A never sees user B’s rows
No secret keys in the bundleSearch the site’s JavaScript for service_role and sk_Only the anon key appears
Role and plan are protectedAsk your developer who can update themOnly the server or an admin
Payments unlock from a webhookOpen the success URL without payingNothing unlocks
Limits live in the databaseAsk where the plan cap is checkedA trigger or server function, not only the form
Schema is in version controlLook for a migrations folder in the repoEvery table and function has a migration

If three or more rows fail, don’t launch paid features yet. If one fails, it’s usually a short, focused fix.

Should you rebuild or fix what you have?

Fix, in most cases. The screens an AI tool produces are usually fine, and your users already know them. What needs work is underneath: policies, a few server functions for payments and limits, error handling, and tests on the money path.

The trade-offs are real, though. When Belka stopped trusting the phone, the unlock stopped being instant. The app now polls for the server’s grant every 1.5 seconds for up to 20 seconds. In Biggo, database errors are ugly, so the forms pre-check the same limits to show a friendly message. Doing it properly means doing some things twice: once for safety and once for the user.

Want me to audit your AI-built app?

This is the work I take on: payments, entitlements and databases that have to be right. You can see the full Belka fix in the case study, and shorter write-ups of the same problems on my engineering notes page.

Here’s how it works. A short call where you describe the problem, then a written plan with scope, timeline and price before any work starts. While I work you get a preview to try, not only a result at the end. Details are on the services page.

If your app was built with AI and you’re not sure what’s underneath, send me a short description. I’ll tell you what I’d check first.

About the screenshots: every image in this post comes from Belka Tech English, captured from the shipped build running on an iPhone simulator.

Questions people ask

Is an app built with Lovable or Bolt safe to launch?

It can be, but not by default. These tools are good at screens and happy paths. Before real users and real money arrive, someone needs to check the database rules, where secrets live, how payments are confirmed and what happens when a request fails or repeats.

Is the Supabase anon key in my frontend a security problem?

No. The anon key is designed to be public. It is only safe if row-level security is turned on for every table and the policies are correct. The service_role key is different: it bypasses all rules and must never reach the browser.

What is the most common serious problem in AI-built apps?

Trusting the app to decide things it should only display. Typical examples are a user’s plan or role stored in a row the user can edit, a success page that unlocks a purchase, and limits checked only in the form.

Do I need to rebuild my app from scratch?

Usually not. In most cases the interface can stay. The work is in the database policies, a few server functions for payments and limits, error handling and tests for the paths that involve money and access.

How do I hire you to audit my app?

Write to contact@stackreda.com or on WhatsApp with a short description and access to the repository if you can share it. I reply with questions, then a written plan with scope, timeline and price before any work starts.
Reda Bellassery
Reda BellasseryFounder of VYNORO · Full-stack & AI developer in Macerata, Italy

I build AI agents, web apps and mobile apps for businesses, and I run my own agency, Barmjli. I write here about what I build and what it taught me.

Keep reading