Spaces:
Paused
Paused
Commit ·
c8fe1a2
1
Parent(s): fb3984d
Add /account/delete: verified-token account data deletion
Browse files
app.py
CHANGED
|
@@ -1206,6 +1206,36 @@ def _paystack_plan_expires(data: dict) -> Optional[str]:
|
|
| 1206 |
return (dt + timedelta(days=31)).isoformat()
|
| 1207 |
|
| 1208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1209 |
@app.post("/paystack/init")
|
| 1210 |
async def paystack_init(request: Request):
|
| 1211 |
"""Initialise a Paystack subscription and return the hosted checkout URL."""
|
|
|
|
| 1206 |
return (dt + timedelta(days=31)).isoformat()
|
| 1207 |
|
| 1208 |
|
| 1209 |
+
@app.post("/account/delete")
|
| 1210 |
+
async def delete_account(request: Request):
|
| 1211 |
+
"""Delete the signed-in user's data (Play Store account-deletion rule).
|
| 1212 |
+
|
| 1213 |
+
Needs a verified Firebase ID token; the body uid fallback is not accepted
|
| 1214 |
+
here. Removes the profile, team membership and saved transcripts. The
|
| 1215 |
+
credit ledger is kept for tax records (it holds only the uid, amounts and
|
| 1216 |
+
Paystack references). The app deletes the Firebase sign-in itself.
|
| 1217 |
+
"""
|
| 1218 |
+
uid = _verified_uid(request)
|
| 1219 |
+
if not uid:
|
| 1220 |
+
raise HTTPException(status_code=401, detail="Sign in again to delete your account.")
|
| 1221 |
+
if not _SUPABASE_URL or not _SUPABASE_KEY:
|
| 1222 |
+
raise HTTPException(status_code=503, detail="Account service unavailable. Try again later.")
|
| 1223 |
+
for table, column in (("transcripts", "user_id"), ("team_members", "firebase_uid"), ("user_profiles", "firebase_uid")):
|
| 1224 |
+
try:
|
| 1225 |
+
resp = _requests.delete(f"{_SUPABASE_URL}/rest/v1/{table}", params={column: f"eq.{uid}"},
|
| 1226 |
+
headers=_sb_headers(), timeout=15)
|
| 1227 |
+
if resp.status_code >= 400 and resp.status_code != 404:
|
| 1228 |
+
logger.warning(f"account delete {table} HTTP {resp.status_code}: {resp.text[:200]}")
|
| 1229 |
+
raise HTTPException(status_code=502, detail="Could not delete your account. Try again later.")
|
| 1230 |
+
except HTTPException:
|
| 1231 |
+
raise
|
| 1232 |
+
except Exception as e:
|
| 1233 |
+
logger.warning(f"account delete {table} failed: {e}")
|
| 1234 |
+
raise HTTPException(status_code=502, detail="Could not delete your account. Try again later.")
|
| 1235 |
+
logger.info(f"Account data deleted for {uid}")
|
| 1236 |
+
return {"deleted": True}
|
| 1237 |
+
|
| 1238 |
+
|
| 1239 |
@app.post("/paystack/init")
|
| 1240 |
async def paystack_init(request: Request):
|
| 1241 |
"""Initialise a Paystack subscription and return the hosted checkout URL."""
|