def save_user_pdfs(user_id, pdf_name, pdf_hash, extracted_text, summary):
print(f"Saving PDF for user_id: {user_id}") # Debugging
if not user_id:
print("Error: user_id is None or missing")
return False
existing_pdfs = get_user_pdfs(user_id)
if len(existing_pdfs)>5:
return False
data = {
"user_id" : user_id,
"pdf_name" : pdf_name,
"pdf_hash" : pdf_hash,
"extracted_text" : extracted_text,
"summary" : summary,
#"created_at": "now()"
}
#user_id = user.id # Ensure this is passed to `save_user_pdfs`
print(f"Authenticated User ID: {user_id}")
try:
if data["user_id"]:
print(f"user id is {data['user_id']}")
response = supabase.table("user_pdfs").insert(data).execute()
print("response", response)
return response.data is not None
except Exception as e:
print(f"{e}")
I am getting this error:
{'code': '42501', 'details': None, 'hint': None, 'message': 'new row violates row-level security policy for table "user_pdfs"'}
Here is my insert policy:
alter policy "Enable insert for users based on user_id" on "public"."user_pdfs"
to authenticated
with check (auth.uid()) = user_id);
Its working when i disable the RLS policy but not with the policy rules. I want that only authenticated users can insert to the user_pdfs table in public database.