Fix redirect issues
Some checks failed
Rust / Test (push) Has been cancelled
Rust / Rustfmt (push) Has been cancelled
Rust / Clippy (push) Has been cancelled
Rust / Code coverage (push) Has been cancelled

Dashboard button now correctly redirects to login page if user is not
logged in while login page redirects to dashboard the other way around.
This commit is contained in:
Alphonse Paix
2025-09-17 23:57:45 +02:00
parent 72d0306e35
commit 044991d623
2 changed files with 17 additions and 4 deletions

View File

@@ -6,12 +6,15 @@ use crate::{
templates::ErrorTemplate,
};
use askama::Template;
use axum::http::{HeaderMap, StatusCode};
use axum::{
Form, Json,
extract::State,
response::{Html, IntoResponse, Response},
};
use axum::{
http::{HeaderMap, StatusCode},
response::Redirect,
};
use secrecy::SecretString;
#[derive(thiserror::Error)]
@@ -65,8 +68,17 @@ pub struct LoginFormData {
password: SecretString,
}
pub async fn get_login() -> Html<String> {
Html(LoginTemplate.render().unwrap())
pub async fn get_login(session: TypedSession) -> Result<Response, LoginError> {
if session
.get_user_id()
.await
.map_err(|e| LoginError::UnexpectedError(e.into()))?
.is_some()
{
Ok(Redirect::to("/admin/dashboard").into_response())
} else {
Ok(Html(LoginTemplate.render().unwrap()).into_response())
}
}
pub async fn post_login(