HX-Redirect to handle redirections with htmx
This commit is contained in:
14
src/routes/admin/logout.rs
Normal file
14
src/routes/admin/logout.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use crate::{routes::AdminError, session_state::TypedSession};
|
||||
use axum::{
|
||||
http::HeaderMap,
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use reqwest::StatusCode;
|
||||
|
||||
#[tracing::instrument(name = "Logging out", skip(session))]
|
||||
pub async fn logout(session: TypedSession) -> Result<Response, AdminError> {
|
||||
session.clear().await;
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("HX-Redirect", "/login".parse().unwrap());
|
||||
Ok((StatusCode::OK, headers).into_response())
|
||||
}
|
||||
Reference in New Issue
Block a user