handler2() -> ... pub async fn is_authenticated(req: Request, next: Next) -> impl IntoResponse { match check_session(req.headers()).await { Ok(true) => next.run(req).await, Ok(false) | Err(_) => (StatusCode::UNAUTHORIZED, "Unauthorized").into_response(), } } 有効なセッションがあれば next、無け れば401 Unauthorized Redirectにしても良い Redirect::temporary(url).into_response()