Bug: JWTAuth How to get db_session #4454
Unanswered
renjianguo666
asked this question in
Q&A
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 |
0 replies
|
next time can you paste code instead of screenshot please @renjianguo666 it's really hard to read ;) |
0 replies
|
sorry, I have learned paste code. using ```python |
0 replies
|
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 |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment



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
All reactions