Moving from fastapi-users¶
Optional reference: how ideas from fastapi-users map to litestar-auth. This library targets Litestar with a plugin entry point, msgspec-oriented schemas, and Transport + Strategy backends — the APIs are different, so use this page as a mental map, not a translation table.
Concept mapping¶
| fastapi-users | litestar-auth |
|---|---|
FastAPIUsers / router registration |
LitestarAuth plugin + LitestarAuthConfig |
UserManager subclass |
BaseUserManager subclass |
| Authentication backends (JWT, cookie, …) | AuthenticationBackend(transport=…, strategy=…) |
| Transport / strategy split (where exposed) | First-class BearerTransport, CookieTransport, JWTStrategy, DatabaseTokenStrategy, RedisTokenStrategy |
Dependency current_user |
request.user after middleware; guards (is_authenticated, …) for enforcement |
| Users router | include_users=True → generated controllers under users_path |
| OAuth routers | oauth_config + provider controllers (see OAuth) |
API shape differences¶
- Framework — Litestar
InitPlugin, DI keys, and guards instead of FastAPI dependencies on routers. - Validation — Prefer msgspec structs (
user_read_schema,user_create_schema, …), not Pydantic models inside the library (your app may still use either elsewhere). When an app-owned registration or update struct keepsemail/passwordfields, importUserEmailField/UserPasswordFieldfromlitestar_auth.schemasso the schema metadata stays aligned with the built-in email and password bounds while runtime password validation still flows throughrequire_password_length. - Email — litestar-auth does not send mail; implement
BaseUserManagerhooks (see Hooks) to enqueue or send messages. - SQLAlchemy — Default user store is
SQLAlchemyUserDatabasewith Advanced Alchemy–friendly patterns; you still own migrations (Alembic /create_all).
Mental model¶
Where you may be used to choosing routers and backends separately, litestar-auth centers on:
- Build one or more
AuthenticationBackendinstances (name, transport, strategy). - Pass them in
LitestarAuthConfig.backends(order matters: first match wins). - Enable HTTP surfaces with flags such as
include_register,totp_config,oauth_config.
Where to read next¶
- Architecture — plugin layers.
- Backends — multiple backends and path prefixes.
- Configuration — full configuration reference.