Newer
Older
cortex-hub / ai-hub / app / api / dependencies.py
# app/api/dependencies.py
from fastapi import Depends, HTTPException, status
from sqlalchemy.orm import Session
from app.db.session import SessionLocal

# This is a dependency
def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()

# This is another common dependency
async def get_current_user(token: str):
    # In a real app, you would decode the token and fetch the user
    if not token:
        raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
    return {"email": "user@example.com", "id": 1} # Dummy user