HX-Redirect to handle redirections with htmx
This commit is contained in:
@@ -6,12 +6,12 @@ use crate::{
|
||||
templates::ErrorTemplate,
|
||||
};
|
||||
use askama::Template;
|
||||
use axum::http::{HeaderMap, StatusCode};
|
||||
use axum::{
|
||||
Form, Json,
|
||||
extract::State,
|
||||
response::{Html, IntoResponse, Redirect, Response},
|
||||
response::{Html, IntoResponse, Response},
|
||||
};
|
||||
use reqwest::StatusCode;
|
||||
use secrecy::SecretString;
|
||||
|
||||
#[derive(thiserror::Error)]
|
||||
@@ -75,7 +75,7 @@ pub async fn post_login(
|
||||
connection_pool, ..
|
||||
}): State<AppState>,
|
||||
Form(form): Form<LoginFormData>,
|
||||
) -> Result<Redirect, LoginError> {
|
||||
) -> Result<Response, LoginError> {
|
||||
let credentials = Credentials {
|
||||
username: form.username.clone(),
|
||||
password: form.password,
|
||||
@@ -104,7 +104,10 @@ pub async fn post_login(
|
||||
.insert_username(form.username)
|
||||
.await
|
||||
.map_err(|e| LoginError::UnexpectedError(e.into()))?;
|
||||
Ok(Redirect::to("/admin/dashboard"))
|
||||
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("HX-Redirect", "/admin/dashboard".parse().unwrap());
|
||||
Ok((StatusCode::OK, headers).into_response())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user