MJ-Prod commited on
Commit
90c77ea
·
1 Parent(s): da65939

added Delete Account

Browse files
Files changed (1) hide show
  1. app.py +40 -1
app.py CHANGED
@@ -88,4 +88,43 @@ def chat_stream(
88
  yield f"data: {json.dumps({'chunk': chunk})}\n\n"
89
  yield "data: [DONE]\n\n"
90
 
91
- return StreamingResponse(generate(), media_type="text/event-stream")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  yield f"data: {json.dumps({'chunk': chunk})}\n\n"
89
  yield "data: [DONE]\n\n"
90
 
91
+ return StreamingResponse(generate(), media_type="text/event-stream")
92
+
93
+
94
+
95
+ @app.delete("/account")
96
+ def delete_account(
97
+ credentials: HTTPAuthorizationCredentials = Depends(security),
98
+ ):
99
+ user = verify_token(credentials.credentials)
100
+ if not user:
101
+ raise HTTPException(status_code=401, detail="Unauthorized")
102
+
103
+ user_id = user["sub"]
104
+
105
+ try:
106
+ from supabase import create_client
107
+ admin_client = create_client(
108
+ os.environ["SUPABASE_URL"],
109
+ os.environ["SUPABASE_SERVICE_KEY"]
110
+ )
111
+
112
+ # 1. Delete bank connections
113
+ admin_client.table("bank_connections")\
114
+ .delete()\
115
+ .eq("user_id", user_id)\
116
+ .execute()
117
+
118
+ # 2. Delete profile
119
+ admin_client.table("profiles")\
120
+ .delete()\
121
+ .eq("id", user_id)\
122
+ .execute()
123
+
124
+ # 3. Delete auth user
125
+ admin_client.auth.admin.delete_user(user_id)
126
+
127
+ return {"status": "account deleted"}
128
+
129
+ except Exception as e:
130
+ raise HTTPException(status_code=500, detail=str(e))