Spaces:
Running
Running
Update main.py
Browse files2875 unmodified lines287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072875 unmodified linesclient = get_supabase()# 1. Verify email exists in profiles (optional but good practice)profile = client.table("profiles").select("id").eq("email", req.email).maybe_single().execute()if not profile.data:# Return same message for security (avoid email enumeration)return {"message": "If the email exists, a reset link has been sent."}# 2. Call Supabase Auth recover endpoint directlyurl = f"{SUPABASE_URL}/auth/v1/recover"headers = {"apikey": SUPABASE_ANON_KEY or SUPABASE_SERVICE_ROLE_KEY,"Content-Type": "application/json"}payload = {"email": req.email}try:async with httpx.AsyncClient(timeout=10.0) as http:resp = await http.post(url, json=payload, headers=headers)if resp.status_code == 200:logger.info(f"Password reset email sent to {req.email}")return {"message": "Password reset email sent. Please check your inbox."}else:logger.error(f"Supabase recover error: {resp.text}")# Still return success to avoid revealing whether email existsreturn {"message": "If the email exists, a reset link has been sent."}except Exception as e:logger.error(f"Reset password error for {req.email}: {e}")return {"message": "If the email exists, a reset link has been sent."}# ------------------------------------------------------------------# Admin: create organisation2875 unmodified lines287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072875 unmodified linesclient = get_supabase()# Verify email existsprofile = client.table("profiles").select("id").eq("email", req.email).maybe_single().execute()if not profile.data:return {"message": "If the email exists, a reset link has been sent."}# Supabase Auth recover endpoint with redirect_tourl = f"{SUPABASE_URL}/auth/v1/recover"headers = {"apikey": SUPABASE_ANON_KEY or SUPABASE_SERVICE_ROLE_KEY,"Content-Type": "application/json"}payload = {"email": req.email,"redirect_to": f"{PRODUCTION_HOST}/kdsiginin" # <-- your frontend page}try:async with httpx.AsyncClient(timeout=10.0) as http:resp = await http.post(url, json=payload, headers=headers)if resp.status_code == 200:return {"message": "Password reset email sent. Please check your inbox."}else:logger.error(f"Supabase recover error: {resp.text}")return {"message": "If the email exists, a reset link has been sent."}except Exception as e:logger.error(f"Reset password error: {e}")return {"message": "If the email exists, a reset link has been sent."}# ------------------------------------------------------------------# Admin: create organisation
main.py+7-7