fastapi_tools.dependencies
¶
FastAPI dependency injection functions.
Functions:
-
get_current_session–Get the current session from the session cookie, if any.
-
get_current_user–Require an authenticated user; raises NotAuthenticatedException otherwise.
-
get_db_session–Yield a placeholder database session.
-
get_optional_user–Get the current user if authenticated, or None.
-
get_session_store–Get session store from app state.
get_current_session
async
¶
get_current_session(
request: Request,
session: Annotated[
str | None, Cookie(alias="session")
] = None,
) -> SessionData | None
Get the current session from the session cookie, if any.
Source code in src/fastapi_tools/dependencies.py
get_current_user
async
¶
get_current_user(
session: Annotated[
SessionData | None, Depends(get_current_session)
],
) -> SessionData
Require an authenticated user; raises NotAuthenticatedException otherwise.
Source code in src/fastapi_tools/dependencies.py
get_db_session
¶
get_optional_user
async
¶
get_optional_user(
session: Annotated[
SessionData | None, Depends(get_current_session)
],
) -> SessionData | None
Get the current user if authenticated, or None.