use axum::{routing::get, Router};
use wacht::middleware::{AuthLayer, RequireAuth};
async fn protected_endpoint(auth: RequireAuth) -> &'static str {
// If we reach this handler, the token was valid!
"You are authenticated."
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Initialize the Wacht SDK from the environment
wacht::init_from_env().await?;
// 2. Attach the AuthLayer to the router
let app = Router::new()
.route("/protected", get(protected_endpoint))
.layer(AuthLayer::new());
// 3. Serve the application
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
axum::serve(listener, app).await?;
Ok(())
}