From 9012cfaae7c49c53590cc2d44ef0e89e5ffabb9c Mon Sep 17 00:00:00 2001 From: Sebastian Jeltsch Date: Sat, 10 May 2025 14:47:01 +0200 Subject: [PATCH] Preserve login ?redirect_to across redirects. --- trailbase-core/src/auth/api/login.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/trailbase-core/src/auth/api/login.rs b/trailbase-core/src/auth/api/login.rs index 0476f474..25b318af 100644 --- a/trailbase-core/src/auth/api/login.rs +++ b/trailbase-core/src/auth/api/login.rs @@ -24,6 +24,7 @@ use crate::constants::{ }; use crate::extract::Either; use crate::rand::generate_random_string; +use crate::util::urlencode; #[derive(Debug, Default, Deserialize, IntoParams)] pub(crate) struct LoginQuery { @@ -97,8 +98,12 @@ pub(crate) async fn login_handler( remove_cookie(&cookies, COOKIE_REFRESH_TOKEN); let url = format!( - "/_/auth/login?alert={msg}", - msg = crate::util::urlencode(&format!("Login Failed: {status}")) + "/_/auth/login?alert={msg}&{redirect_to}", + msg = urlencode(&format!("Login Failed: {status}")), + redirect_to = redirect.map_or_else( + || "".to_string(), + |r| format!("redirect_to={}", urlencode(&r)) + ), ); return Ok(Redirect::to(&url).into_response());