We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 48b3182 commit c5d3052Copy full SHA for c5d3052
1 file changed
packages/integrations/shield-axum/src/extract.rs
@@ -61,3 +61,23 @@ impl<S: Send + Sync, U: User + Clone + 'static> FromRequestParts<S> for ExtractU
61
))
62
}
63
64
+
65
+pub struct UserRequired<U: User>(pub U);
66
67
+#[async_trait]
68
+impl<S: Send + Sync, U: User + Clone + 'static> FromRequestParts<S> for UserRequired<U> {
69
+ type Rejection = (StatusCode, &'static str);
70
71
+ async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
72
+ parts
73
+ .extensions
74
+ .get::<Option<U>>()
75
+ .cloned()
76
+ .ok_or((
77
+ StatusCode::INTERNAL_SERVER_ERROR,
78
+ "Can't extract Shield user. Is `ShieldLayer` enabled?",
79
+ ))
80
+ .and_then(|user| user.ok_or((StatusCode::UNAUTHORIZED, "Unauthorized")))
81
+ .map(UserRequired)
82
+ }
83
+}
0 commit comments