Bug: JWTAuth How to get db_session #4454
Replies: 6 comments 1 reply
-
|
maybe someone more familiar with the sqlalchemy plugin can confirm but generally speaking the session should be accessible in the ASGIConnection object in the app state, now i dont know under which key so something like |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I found it. |
Beta Was this translation helpful? Give feedback.
-
|
next time can you paste code instead of screenshot please @renjianguo666 it's really hard to read ;) |
Beta Was this translation helpful? Give feedback.
-
|
sorry, I have learned paste code. using ```python |
Beta Was this translation helpful? Give feedback.
-
|
You can actually do this without having to go through the state: async def retrieve_user_handler(
handler: BaseRouteHandler,
connection: ASGIConnection
) -> User | None:
sqlalchemy_plugin = connection.app.plugins.get(SQLAlchemyPlugin)
config = sqlalchemy_plugin.config
async with config.create_session_maker() as session:
pass |
Beta Was this translation helpful? Give feedback.



Uh oh!
There was an error while loading. Please reload this page.
-
Description
https://docs.litestar.dev/2/usage/security/jwt.html
retrieve_user_handler How to get db_session ???
URL to code causing the issue
No response
MCVE
Steps to reproduce
Screenshots
No response
Logs
Litestar Version
2.18.0
Platform
Beta Was this translation helpful? Give feedback.
All reactions