use axum::{Router, routing::get, Json};
use wacht::middleware::{AuthLayer, RequireAuth};
use serde_json::json;
// This handler will ONLY run if the request has a valid Wacht Bearer token
async fn get_profile(auth: RequireAuth) -> Json<serde_json::Value> {
Json(json!({
"message": format!("Hello, {}!", auth.user_id),
"session": auth.session_id
}))
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize global configuration and fetch public signing keys
wacht::init_from_env().await?;
let app = Router::new()
.route("/profile", get(get_profile))
.layer(AuthLayer::new());
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
axum::serve(listener, app).await?;
Ok(())
}