diff --git a/app/main.py b/app/main.py index 69dfcf8..3d46e18 100644 --- a/app/main.py +++ b/app/main.py @@ -1,17 +1,21 @@ from fastapi import FastAPI from fastapi.security import OAuth2PasswordBearer +from contextlib import asynccontextmanager from .controllers import userManager, cardManager, groupManager, aaManager from .services.database import create_db_and_tables from .services.auth import token_router, create_first_user oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") -app = FastAPI() -@app.on_event("startup") -def on_startup(): +@asynccontextmanager +async def lifespan(app: FastAPI): create_db_and_tables() create_first_user() print("Database created and tables initialized.") + yield + +app = FastAPI(lifespan=lifespan) + app.include_router(token_router)