expenses_ai / db.py
Sabithulla's picture
Create db.py
3b0dd64 verified
raw
history blame contribute delete
897 Bytes
from supabase import create_client
SUPABASE_URL = "https://gcsbazzmtivhmuietajs.supabase.co"
SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imdjc2JhenptdGl2aG11aWV0YWpzIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzI5NjE3MDIsImV4cCI6MjA4ODUzNzcwMn0.g3ciFwNv6ei6BMsyWTCgsJqgQcqKIqaKhqK4GCAL5_E"
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
def get_user_expenses(access_token):
try:
# Get logged-in user
user_response = supabase.auth.get_user(access_token)
user = user_response.user
if not user:
return []
user_id = user.id
# Fetch only that user's data
response = supabase.table("expenses") \
.select("*") \
.eq("user_id", user_id) \
.execute()
return response.data
except Exception as e:
print("DB ERROR:", e)
return []