From 64931189c7d566e32a5f50bad6e16a19dbaab2c9 Mon Sep 17 00:00:00 2001 From: Wren Turkal Date: Thu, 16 Jan 2025 03:56:12 -0800 Subject: [PATCH] Improve logout example (#496) The current example for logout is not show a complete example. I have added a couple lines to handle the case where a logged out user tries to logout again. --- actix-identity/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/actix-identity/src/lib.rs b/actix-identity/src/lib.rs index aa3f98dba..5e30eb951 100644 --- a/actix-identity/src/lib.rs +++ b/actix-identity/src/lib.rs @@ -74,8 +74,10 @@ async fn login(request: HttpRequest) -> impl Responder { } #[post("/logout")] -async fn logout(user: Identity) -> impl Responder { - user.logout(); +async fn logout(user: Option) -> impl Responder { + if let Some(user) = user { + user.logout(); + } HttpResponse::Ok() } ```