-
-
Notifications
You must be signed in to change notification settings - Fork 382
Allow handlers to take Option<JWT> as a parameter
#1662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Edit: see post below This would be a big improvement for me. Not sure how else to create a frontpage on the html/htmx stack, with different state depending on the logged in status, apart from doing multiple calls. |
|
I found a solution for this, as it's already solved in Axum by handling extractor rejections with Result. So you can wrap JWT in Result like: and handle the error if there is no auth present |
|
@askor yeah, I should have thought of that... I think this is still OK though as it can bubble up JWT format/validity errors separate from JWT presence. |
|
thanks @pantsman0, |
|
@kaplanelad Can you provide a little more guidance? There are no existing JWT tests in that folder, are you OK for me to just have at it? I have made changes to the tests in |
|
Sure, lt me open a pr that testing the current auth flow, then you can update your branch and adding yours |
|
I’ve opened a PR for the auth tests: #1671. |
|
@kaplanelad sorry for the ping, I don't know if you get one when I put an update. I fixed the style CI fail. |
This PR adds an implementation of
OptionalFromRequestParts<S> for JWT, allowing handler functions in controllers such aspub async fn render_home(jwt: Option<auth::JWT>, ViewEngine(v): ViewEngine<TeraView>) -> Result<Response>for things like redirecting to the login page if the JWT is not present in a cookie.