1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-01-22 06:45:56 +01:00

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.
This commit is contained in:
Wren Turkal 2025-01-16 03:56:12 -08:00 committed by GitHub
parent 265b213123
commit 64931189c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -74,8 +74,10 @@ async fn login(request: HttpRequest) -> impl Responder {
} }
#[post("/logout")] #[post("/logout")]
async fn logout(user: Identity) -> impl Responder { async fn logout(user: Option<Identity>) -> impl Responder {
user.logout(); if let Some(user) = user {
user.logout();
}
HttpResponse::Ok() HttpResponse::Ok()
} }
``` ```