from contextlib import asynccontextmanager
from starlette.applications import Starlette
from nexfetch_auth import nexfetch_auth
from nexfetch_auth.db.adapters.sqlalchemy import sqlalchemy_adapter
from nexfetch_auth.integrations.starlette import mount as mount_auth
@asynccontextmanager
async def lifespan(app):
auth = await nexfetch_auth(
secret="your-secret-key",
database=await sqlalchemy_adapter("sqlite+aiosqlite:///auth.db"),
)
app.router.routes.append(mount_auth(auth, "/api/auth"))
yield
await auth.close()
app = Starlette(lifespan=lifespan)