Hey Folks,
I am currently trying my luck at putting together the examples from the docs. I used the SQLAlchemy-Plugin to init my DB-Connection like so:
sqlalchemy_config = SQLAlchemyConfig(
connection_string="sqlite+aiosqlite:///test.sqlite", dependency_key="async_session"
)
sqlalchemy_plugin = SQLAlchemyPlugin(config=sqlalchemy_config)
dto_factory = DTOFactory(plugins=[sqlalchemy_plugin])
I can use the dependecy async_session in my UserController for basic CRUD operations by including
async_session: AsyncSession in the function params and can access the session in the function
When trying to implement the JWT-Backend I implemented the retrieve_user_handler as follows:
async def retrieve_user_handler(token: Token, connection: ASGIConnection, async_session: AsyncSession
) -> User | None:
user_sub = token.sub
if user_sub:
res = await async_session.scalars(select(User).where(User.name == user_sub))
req_user: User | None = res.one_or_none()
return req_user
return None
The async_session is not injected like in the UserController. What is the Starlite way to get the session for the handler? Is there some kind of magic with Provide() that I am missing?