Skip to content

Commit

Permalink
Improve logout example (#496)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wt authored Jan 16, 2025
1 parent 265b213 commit 6493118
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions actix-identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Identity>) -> impl Responder {
if let Some(user) = user {
user.logout();
}
HttpResponse::Ok()
}
```
Expand Down

0 comments on commit 6493118

Please sign in to comment.