# Lovable + Supabase to Google Play Playbook: RLS Security, Deep-Link Auth & Account Deletion

> Package full-stack Lovable (React + Tailwind + shadcn/ui + Supabase) apps into Google Play `.aab` releases — mastering OAuth deep-link callbacks, Row-Level Security audits, reviewer bypass logins, and Edge Function account deletion.

- **Canonical URL**: https://gootester.com/frameworks/lovable-supabase-android
- **Config File**: capacitor.config.ts & supabase/functions/delete-account/index.ts
- **Build Command**: `npm run build && npx cap sync android && cd android && ./gradlew bundleRelease`

```typescript
import { createClient } from "@supabase/supabase-js";
import { App } from "@capacitor/app";

// Safe ONLY when every Postgres table enforces strict Row Level Security (RLS)!
export const supabase = createClient(
  import.meta.env.VITE_SUPABASE_URL,
  import.meta.env.VITE_SUPABASE_ANON_KEY,
  { auth: { flowType: "pkce", detectSessionInUrl: false, persistSession: true } }
);

// Exchange PKCE code when Android App Link returns from Google OAuth / Magic Link:
App.addListener("appUrlOpen", async ({ url }) => {
  if (url.includes("code=")) {
    const parsed = new URL(url);
    const code = parsed.searchParams.get("code");
    if (code) await supabase.auth.exchangeCodeForSession(code);
  }
});
```

## Critical Play Console Gotchas
1. **Supabase OAuth / Magic Links redirecting to `localhost:3000` inside mobile Chrome**: Leaving Supabase Auth's Site URL or `redirectTo` set to `http://localhost:3000` causes Google Sign-In and password-reset links on Android phones to fail with `ERR_CONNECTION_REFUSED`. Register an Android App Link (`https://app.example.com/auth/callback`) backed by `assetlinks.json` + PKCE exchange.
2. **Bundling `VITE_SUPABASE_ANON_KEY` while a Postgres table has RLS disabled**: Your Supabase `anon` key is extractable from every shipped APK by design; if even a single Lovable-generated migration forgot `ALTER TABLE ... ENABLE ROW LEVEL SECURITY`, anyone can read or wipe all user rows via REST.
3. **Client-side `supabase.auth.signOut()` pretending to be 'Delete Account'**: Google Play's Account Deletion policy requires permanently erasing the user's `auth.users` record and personal rows — which requires invoking a server-side Supabase Edge Function holding `SUPABASE_SERVICE_ROLE_KEY` (`supabaseAdmin.auth.admin.deleteUser(user.id)`), never shipping the service-role key inside the APK!
4. **Magic-link-only login blocking Google Play `App access` human reviewers**: Reviewers cannot click magic links sent to your inbox. Enable standard Email + Password login in Supabase Auth alongside Magic Links/OAuth so you can give Play Console a static `support@example.com` demo account.

## Hardening Supabase Auth, PKCE Deep Links, and RLS Before Uploading Your AAB

**Lovable** paired with **Supabase** has become one of the most productive full-stack workflows for indie founders — automatically generating React + Tailwind UI, Postgres schemas, authentication, and Edge Functions from natural language. Moving that web app onto Google Play requires tightening three mobile-specific seams: **PKCE Deep-Link Auth**, **Row-Level Security (`RLS`)**, and **Dual-Surface Account Deletion**.
First, audit your Supabase Security Advisor dashboard to confirm `0` tables lack RLS policies and `0` Edge Functions accidentally expose `SUPABASE_SERVICE_ROLE_KEY` to client code. Second, configure Android App Links (`/.well-known/assetlinks.json` containing both your Play App Signing SHA-256 and local upload SHA-256 via `/tools/digital-asset-links-assetlinks-generator`) so Supabase PKCE OAuth callbacks reopen your native app cleanly instead of stranding users in a mobile browser tab.
Third, enable Email + Password authentication in Supabase and seed a dedicated, non-expiring demo account (`support@example.com`) with realistic sample data so Google Play reviewers clear `App content -> App access` on the very first pass.

## Implementing True Supabase Account Deletion (In-App + Web URL)

Every Lovable + Supabase app supporting user sign-up triggers Google Play's mandatory dual-surface Account Deletion rule under `App content -> Data safety`. Inside your app's Settings screen, wire a `Delete My Account` confirmation dialog that calls an authenticated Supabase Edge Function (`delete-account`), verifies the caller's JWT (`supabaseClient.auth.getUser()`), cascades personal storage/row cleanup, and invokes `supabaseAdmin.auth.admin.deleteUser(uid)`.
Alongside that in-app button, deploy a public, login-free HTTPS web deletion page (`https://example.com/delete-account`, easily generated via `/tools/google-play-privacy-policy-data-deletion-generator`) so users who have already uninstalled your Android app can still request complete account and data erasure.

## Stress-Testing Multi-Tenant Flows Across 12–25 Human Closed Testers

Database RLS bugs and race conditions often stay invisible when you test solely as `User #1` on your laptop, then break immediately when 15 concurrent external testers sign up with independent accounts on Day 1 of Closed Testing!
Once your Closed Testing track is live and `testers@gootester.com` is verified (starting GOOtester's service clock), let 12, 15, or 25 consented human testers ($6/$12/$20 one-time) exercise real multi-user onboarding while Standard/Premium's separate physical-device ARM64 ADB QA verifies startup performance and 0 crashes.
