@@ -110,18 +110,18 @@ pub async fn auth_middleware(mut req: Request, next: Next, store: Arc<AuthStore>
110110 let Some ( val) = req. headers ( ) . get ( axum:: http:: header:: AUTHORIZATION ) else {
111111 let c = UNAUTH_COUNT . fetch_add ( 1 , Ordering :: Relaxed ) ;
112112 if c. is_multiple_of ( 10 ) { warn ! ( "auth.unauthorized.missing_header" ) ; }
113- Err ( axum:: response:: Response :: builder ( ) . status ( StatusCode :: UNAUTHORIZED ) . body ( axum:: body:: Body :: empty ( ) ) . unwrap ( ) )
113+ return Err ( axum:: response:: Response :: builder ( ) . status ( StatusCode :: UNAUTHORIZED ) . body ( axum:: body:: Body :: empty ( ) ) . unwrap ( ) ) ;
114114 } ;
115115 let Ok ( hdr) = val. to_str ( ) else {
116116 let c = UNAUTH_COUNT . fetch_add ( 1 , Ordering :: Relaxed ) ;
117117 if c. is_multiple_of ( 10 ) { warn ! ( "auth.unauthorized.bad_header" ) ; }
118- Err ( axum:: response:: Response :: builder ( ) . status ( StatusCode :: UNAUTHORIZED ) . body ( axum:: body:: Body :: empty ( ) ) . unwrap ( ) )
118+ return Err ( axum:: response:: Response :: builder ( ) . status ( StatusCode :: UNAUTHORIZED ) . body ( axum:: body:: Body :: empty ( ) ) . unwrap ( ) ) ;
119119 } ;
120120 let prefix = "Bearer " ;
121121 if !hdr. starts_with ( prefix) {
122122 let c = UNAUTH_COUNT . fetch_add ( 1 , Ordering :: Relaxed ) ;
123123 if c. is_multiple_of ( 10 ) { warn ! ( "auth.unauthorized.bad_schema" ) ; }
124- Err ( axum:: response:: Response :: builder ( ) . status ( StatusCode :: UNAUTHORIZED ) . body ( axum:: body:: Body :: empty ( ) ) . unwrap ( ) )
124+ return Err ( axum:: response:: Response :: builder ( ) . status ( StatusCode :: UNAUTHORIZED ) . body ( axum:: body:: Body :: empty ( ) ) . unwrap ( ) ) ;
125125 }
126126 let token = & hdr[ prefix. len ( ) ..] ;
127127 // Hash the token and lookup
@@ -133,7 +133,7 @@ pub async fn auth_middleware(mut req: Request, next: Next, store: Arc<AuthStore>
133133 if let Some ( info) = store. by_hash . get ( & arr) {
134134 // Constant-time confirmation (redundant as hash-length fixed, but good practice)
135135 if !ct_eq ( & arr, & info. token_hash ) {
136- Err ( axum:: response:: Response :: builder ( ) . status ( StatusCode :: UNAUTHORIZED ) . body ( axum:: body:: Body :: empty ( ) ) . unwrap ( ) )
136+ return Err ( axum:: response:: Response :: builder ( ) . status ( StatusCode :: UNAUTHORIZED ) . body ( axum:: body:: Body :: empty ( ) ) . unwrap ( ) ) ;
137137 }
138138 // Create stable user_id from sha256(token) first 16 bytes
139139 let hash = Sha256 :: digest ( token. as_bytes ( ) ) ;
@@ -157,7 +157,7 @@ pub async fn auth_middleware(mut req: Request, next: Next, store: Arc<AuthStore>
157157// Route-level RBAC guard; min_role enforced if auth is enabled; otherwise pass-through
158158pub async fn require_role ( req : Request , next : Next , store : Arc < AuthStore > , min_role : Role ) -> Result < axum:: response:: Response , axum:: response:: Response > {
159159 if !is_auth_enabled ( & store) {
160- Ok ( next. run ( req) . await )
160+ return Ok ( next. run ( req) . await ) ;
161161 }
162162 if let Some ( ctx) = req. extensions ( ) . get :: < UserContext > ( ) {
163163 if ctx. role . allows ( min_role) {
0 commit comments