34 lines
953 B
Python
34 lines
953 B
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(user: dict = Depends(get_current_user)):
|
|
return {
|
|
"id": user.get("sub"),
|
|
"email": user.get("email"),
|
|
"role": user.get("role"),
|
|
"tenant_id": user.get("tenant_id", "unknown")
|
|
}
|