Skip to main content

FastAPI

from contextlib import asynccontextmanager
from fastapi import FastAPI
from nexfetch_auth import nexfetch_auth
from nexfetch_auth.db.adapters.sqlalchemy import sqlalchemy_adapter


@asynccontextmanager
async def lifespan(app: FastAPI):
auth = await nexfetch_auth(
secret="your-secret-key",
database=await sqlalchemy_adapter("sqlite+aiosqlite:///auth.db"),
)
app.mount("/api/auth", auth.app)
yield
await auth.close()


app = FastAPI(lifespan=lifespan)

auth.app is a standard ASGI application. app.mount(prefix, asgi_app) is FastAPI's built-in way to mount sub-applications.