One pattern that covers most of this, with the caveat that the privileged routes can't be fenced by policies: 1\. **Tombstone first.** Add a `status` (or `deleting_at`) column on the owning entity and set it before anything is removed. Make your `storage.objects` INSERT/UPDATE policies require an active owner, e.g. the first folder of the path maps to a project row where `status = 'active'` and the owner is `auth.uid()`. Client uploads, including resumable (TUS) uploads made with the user's JWT, go through those policies, so new writes stop once the flag flips. 2\. **Signed upload URLs** are checked when you create them, not when the upload lands, and they stay valid for a while (2 hours, per the Storage docs). Mint them only from an Edge Function that checks the status, and have the cleanup wait past that window before the final sweep. 3\. **Service role and S3 access keys bypass RLS.** Nothing in policies will stop them, so keep those keys only in the deletion worker and your own backend, and have that code check the tombstone itself. 4\. **Delete files through the Storage API** (list the prefix, then `remove`), not by deleting rows from `storage.objects`, which leaves the files behind. Then delete the database rows, then the Auth user (`auth.admin.deleteUser`). For account deletion, ban or sign out the user first so no fresh sessions are issued while the job runs; existing JWTs still work until they expire, which is another reason step 1 matters. 5\. **Orphan sweep.** A scheduled job (pg_cron calling an Edge Function) that lists objects whose prefix has no active owner row and removes them handles in-flight uploads that landed mid-delete, and retries are safe because each step is idempotent. Before launch, test it with two accounts and a large resumable upload started just before you hit delete, and confirm the object is gone after the sweep.
For a Lovable → hosted Supabase move where the same Google identity already points at two Auth users, I would treat merge as last resort. First: private window + Google sign-in on the destination project only, and confirm which auth.users id you actually land on. If both users must survive, keep them separate and map app data with your own legacy_user_id column rather than forcing GoTrue to move the identity. Before any Admin API linking: export both users, revoke refresh tokens on a test account, and have a rollback note for Site URL / redirect URLs. I work on AppFirstAid — happy to sanity-check the post-migration Google path from the outside if useful: https://appfirstaid.com/?ref=gh-53053
Nice build — shared flats need solid invite/expense boundaries. One outside check on app.manawg.com before you push for users: the home page currently sends robots noindex, so Google won't list it (often left from staging). Drop that meta (or set index,follow) once you're ready to be found, and add a sitemap.xml. I work on AppFirstAid and ran our free outside check: https://appfirstaid.com/r/caabf6f4-0f3a-4ead-b0ab-63b482b82fdc?ref=gh-53083
You're not imagining it: after logout or an RLS tighten, a browser can still GET an object it already fetched because the JWT is still valid until expiry and the response may be cached. Practical mitigations: 1. Serve authenticated objects with `Cache-Control: private, no-store` (and avoid long-lived CDN cache on that path). 2. 2. Prefer short-lived signed URLs for downloads instead of relying on the session JWT alone. 3. 3. On logout, clear client storage of any object URLs you handed out and don't reuse them. If it still reproduces after a hard refresh with a fresh anonymous session, that's a stronger signal for the Storage team.
Nice to see a no-build-step setup on Supabase. I work on AppFirstAid and ran our free outside check on smoothlinesystems.com. Nothing urgent: https is on, and no keys or private files showed up. The one gap is that the site sends none of the four browser safety headers (Strict-Transport-Security, Content-Security-Policy, X-Frame-Options, X-Content-Type-Options). It's served by Apache, so a few `Header always set` lines in the server config or .htaccess cover it. Since IT firms self-host from your guide, adding those lines to the guide would carry the fix to every install. Report: https://appfirstaid.com/r/fb58be23-d007-4987-97dc-debc652a1199?ref=gh-52780
Sumando a la respuesta de arriba, un ejemplo concreto de filtrar por `auth.uid()` dentro de la misma consulta, que hace que la llamada individual y por lotes se comporten igual (solo vuelven las filas permitidas aunque el array mezcle ids de otro usuario): ```sql create or replace function public.get_settings(p_ids uuid[]) returns setof public.settings language sql security definer set search_path = '' as $$ select s.* from public.settings s join public.memberships m on m.resource_id = s.resource_id where s.resource_id = any(p_ids) and m.user_id = (select auth.uid()); $$; revoke execute on function public.get_settings(uuid[]) from public, anon; grant execute on function public.get_settings(uuid[]) to authenticated; ``` Postgres da `execute` a `public` por defecto, por eso el `revoke`. Para simular usuarios en las pruebas sin credenciales reales (dentro de `begin; ... rollback;` o con pgTAP): ```sql set local role authenticated; set local request.jwt.claims = '{"sub":"<uuid ficticio de A>","role":"authenticated"}'; select * from public.get_settings(array['<recurso de A>','<recurso de B>']::uuid[]); -- debe devolver solo la fila de A; un id inexistente debe verse igual que el de B (0 filas, sin error que revele si existe) ```
Nice split. On mobile I'd put the two journeys as two short lines right under the headline: "You: make the gift (free account, about a minute)" and "Them: tap the link. No app, no sign-up." Add one phone-sized preview of what the recipient sees and both questions are answered before anyone scrolls. Since recipients open gifts without an account, one thing worth testing on the data side: the gift link should use a long random ID, and your Supabase policies should let a logged-out visitor read one gift by that exact ID but never list the gifts table. Open a gift link in a private window, then try a request for the table with no filter; it should come back empty. I ran our free outside check on sendlove.io: no secret keys in the public code, /login and /signup load, and sign-in links point at your live domain. The only small item was a missing Content-Security-Policy header. What outside checks can and can't see: https://appfirstaid.com/guides/what-built-in-security-scans-miss I work on AppFirstAid; the free check is at https://appfirstaid.com
On the account boundary: letting people finish the exercise before sign-up feels right to me, as long as the result survives the sign-up step (worth testing with a brand-new email, including the confirm-email redirect on the live domain). I also ran a free outside check on the live site and it looks clean: no exposed keys or config files, and /login and /pricing load. One small thing worth adding is the three browser safety headers (Content-Security-Policy, X-Frame-Options, X-Content-Type-Options), which Vercel lets you set in vercel.json. Disclosure: I work on AppFirstAid, the tool I used; report here if useful: https://appfirstaid.com/r/077998dd-0afd-4ac3-a1d4-58561f558144