diff --git a/nixin_farm_ssr/assets/views/home/login.html b/nixin_farm_ssr/assets/views/home/login.html
index d84684c..2b43a9d 100644
--- a/nixin_farm_ssr/assets/views/home/login.html
+++ b/nixin_farm_ssr/assets/views/home/login.html
@@ -21,7 +21,7 @@ Login
-->
-
+
Sign in to your account
diff --git a/nixin_farm_ssr/src/controllers/home.rs b/nixin_farm_ssr/src/controllers/home.rs
index 89697a6..d0b3e06 100644
--- a/nixin_farm_ssr/src/controllers/home.rs
+++ b/nixin_farm_ssr/src/controllers/home.rs
@@ -8,8 +8,8 @@ use axum::{
extract::State,
//extract::Query,
response::{/*IntoResponse,*/ Redirect},
- http::StatusCode,
//Json,
+ http::{StatusCode, header::{self, HeaderValue, HeaderMap}},
Form};
use axum_extra::extract::cookie::{CookieJar, Cookie};
@@ -128,7 +128,11 @@ pub async fn do_register(
let res = AuthMailer::send_welcome(&ctx, &user).await;
match res {
Ok(()) => {
- return format::redirect("/login");
+ let mut headers = HeaderMap::new();
+ //ToDo: modifiy below to avoid using ugly unwrap
+ headers.insert("HX-Location", "/".parse().unwrap());
+
+ return Ok(headers.into_response());
}
Err(err) => {
return views::home::error(&v,&format!("failed to send welcome email: {}",err.to_string()));
@@ -179,11 +183,25 @@ pub async fn do_login(
else {
return Ok((jar, views::home::error(&v,"Login failed: invalid email or password")));
};
+ let mut headers = HeaderMap::new();
+ //ToDo: modifiy below to avoid using ugly unwrap
+ headers.insert(header::AUTHORIZATION, HeaderValue::from_str(&token).unwrap());
+ headers.insert("HX-Location", "/".parse().unwrap());
+
+ // We do not really need to return the index view in the response body
+ // because the HX-Location header will trigger htmx to fetch it from
+ // the client.
+ // We are doing it here only to test if it allows degrading gracefully
+ // on java script disabled clients.
+ // See do_register() for an implementation of htmx redirect with
+ // an empty body
+ let index_view = views::home::index(&v,&user).unwrap();
+ // Also we are returning the JWT token both in a header and in a cookie
+ // This is also done for test purposes only.
+ // Only one of these should be done, the one used in the auth configuration.
Ok((
- // the updated jar must be returned for the changes
- // to be included in the response
jar.add(Cookie::new("token", token)),
- Ok(Redirect::to("/").into_response()),))
+ Ok((headers, index_view).into_response()),))
}
_ => {
return Ok((jar, views::home::error(&v,"Login failed: you need to provide an email and a password")));