Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Identity
✓ use actix_identity::Identity;
Set up Actix Web with identity middleware and a protected endpoint.
use actix_web::{web, App, HttpServer, HttpResponse};
use actix_identity::{Identity, IdentityMiddleware};
async fn index(user: Option<Identity>) -> HttpResponse {
if let Some(id) = user {
HttpResponse::Ok().body(format!("Logged in as {}", id.id().unwrap()))
} else {
HttpResponse::Unauthorized().finish()
}
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.wrap(IdentityMiddleware::default())
.route("/", web::get().to(index))
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}
Audit
Dependencies
No dependency data recorded yet.