pub async fn logout<B: Default>(parts: &Parts) -> Response<B>Expand description
End the user’s access everywhere with a server-side call to Stackure, clear the app’s session cookie and redirect to Stackure.
Mount it for every method on the logout path. Trigger it with a form or button that POSTs from the app’s own page; a link or any other request is sent to Stackure’s sign-out page, where the user confirms, with no call made and the cookie left in place.
A request counts as coming from the app’s own page when it is a POST with
Sec-Fetch-Site: same-origin or, when that header is absent, with an
Origin whose host and port match Host and whose scheme is https if
the request arrived over HTTPS. A request that repeats Sec-Fetch-Site,
Origin or Host never counts.
If the call fails, the redirect goes to Stackure’s sign-out page instead, where the user can finish signing out.
Asynchronous: awaiting it yields the 303 Response, never an error.
§Example
async fn logout(parts: http::request::Parts) -> axum::response::Response {
stackure::logout(&parts).await
}
let app: Router = Router::new().route("/logout", any(logout));