complycore/backend/main.py

39 lines
1.1 KiB
Python

# backend/main.py
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from sqlalchemy import text
from db.session import engine
from fastapi import Depends
from auth.jwt import get_current_user
app = FastAPI()
@app.get("/healthz")
def health_check():
return {"status": "ok"}
@app.get("/supabase-check")
def supabase_check():
try:
with engine.connect() as conn:
result = conn.execute(text("SELECT current_database(), current_user;"))
db, user = result.fetchone()
return {"status": "connected", "db": db, "user": user}
except Exception as e:
return JSONResponse(status_code=500, content={"status": "error", "error": str(e)})
@app.get("/me")
def me(current: dict = Depends(get_current_user)):
usr = current["user"] # users table row
tenant = current["tenant"] # tenant row or None
return {
"id": usr["id"],
"email": usr["email"],
"role": current["scopes"],
"tenant_id": tenant["id"] if tenant else "unknown",
}