Fix deprecation warning by changing on_event to asynccontesxtmanager

This commit is contained in:
2026-05-16 17:10:40 +02:00
parent 0337a90f15
commit 5c2e58d5d0

View File

@@ -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)