Repository navigation
feat: CurrentUser + OptionalCurrentUser extractors with JWT validation - #13
Merged
Merged
Conversation
#2) - Replace placeholder middleware with full FromRequestParts<AppState> impl - CurrentUser: reads session cookie, validates JWT via validate_jwt, returns 401 on failure - OptionalCurrentUser: never rejects, returns Option<CurrentUser> - Generic over state S where AuthConfig: FromRef<S> (avoids circular dep) - Add FromRef<AppState> for AuthConfig in rungu-api - Add axum-extra cookie feature to workspace deps - Export OptionalCurrentUser from rungu-auth lib - 6 unit tests (valid token, no cookie, invalid token — for both extractors)
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-cli · BYOK · MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the placeholder middleware with full
FromRequestPartsextractors that read the session cookie and validate the JWT.Closes #2
Extractors
CurrentUsersessioncookie → validates JWT viavalidate_jwt(token, app_secret)401 Unauthorizedif no cookie or invalid tokenSwhereAuthConfig: FromRef<S>OptionalCurrentUserOption<CurrentUser>Changes
crates/rungu-auth/src/middleware.rs— full implementation (was 39 → 217 lines)crates/rungu-auth/src/lib.rs— exportOptionalCurrentUsercrates/rungu-api/src/lib.rs—impl FromRef<AppState> for AuthConfigcrates/rungu-auth/Cargo.toml— added axum-extra dependencyCargo.toml— addedaxum-extrawithcookiefeature to workspaceDesign decision
The extractors are generic over
SwhereAuthConfig: FromRef<S>to avoid a circular dependency betweenrungu-authandrungu-api. TheFromRef<AppState>impl lives inrungu-api.Test plan
cargo check --workspace✅cargo test --package rungu_auth— 6/6 pass ✅cargo clippy -- -D warnings✅cargo fmt --check✅