Skip to content

Migrating to 0.11

0.11 is a breaking API cleanup. The runtime keeps the same auth behavior, but the construction, database factory, and route-dependency surfaces are narrower.

Construct FastAuth directly

Build a FastAuthOptions object first, then pass it to FastAuth.

from pydantic import SecretStr

from fastauth import FastAuth, FastAuthOptions, email_password
from fastauth.database import memory

options = FastAuthOptions(
    secret_key=SecretStr(app_settings.auth_secret),
    database=memory(),
)
auth = FastAuth(options, plugins=[email_password()])

Removed spellings:

  • create_auth(...)
  • FastAuth.configure(...)
  • FastAuth.local_dev(...)
  • FastAuth.production(...)

For local HTTP development, pass CookieOptions(secure=False) explicitly. For production, set deployment="production" on FastAuthOptions.

Use keyword database handles

Database factories now take backend handles by keyword so configuration reads the same way across backends:

from fastauth.database import custom, mongo, postgres

database=mongo(database=mongo_database)
database=postgres(url="postgresql+asyncpg://user:pass@localhost/myapp")
database=custom(adapter=adapter, backend=DatabaseBackendKind.POSTGRES)

MongoDatabaseOptions.database is typed as MongoDatabase, an alias for PyMongo's async database type when type checking is available.

Use short duration inputs

Duration fields still store datetime.timedelta, but options now accept integer or float seconds and short strings:

SessionOptions(expires_in="7d", idle_timeout="30m")
RateLimitOptions(window=60)
LockoutOptions(window="5m")
RefreshTokenOptions(max_age="14d", absolute_max_age="4w")

Supported suffixes are ms, s, m, h, d, and w.

Use auth.depends

FastAPI dependencies now live in one namespace:

from typing import Annotated

from fastapi import Depends
from fastauth import UserView

CurrentUser = Annotated[UserView, Depends(auth.depends.user())]

@app.get("/me")
async def me(user: CurrentUser) -> UserView:
    return user

Available dependencies:

  • auth.depends.user() returns UserView or raises 401.
  • auth.depends.optional_user() returns UserView | None.
  • auth.depends.session() returns SessionContext or raises 401.
  • auth.depends.optional_session() returns SessionContext | None.

Removed route dependency spellings include auth.require_user, auth.optional_user, auth.require_session, auth.optional_session, auth.get_current_user, and auth.get_current_session.