@@ 1,5 1,6 @@
use axum::{ async_trait, RequestPartsExt };
use axum::extract::{ FromRef, FromRequestParts, State };
+use axum::http::Uri;
use axum_extra::extract::cookie::CookieJar;
use axum::http::request::Parts;
use crate::http::AppState;
@@ 28,6 29,9 @@ where
let cookies = parts.extract::<CookieJar>()
.await
.expect("Infallible is");
+ let path = parts.extract::<Uri>()
+ .await
+ .expect("Infallible is");
let session_cookie = cookies.get("session_id");
match session_cookie {
@@ 36,11 40,11 @@ where
match user {
Some(user) => Ok(AuthenticatedUser { user, phantom: PhantomData }),
// Session cookie is present but invalid; user needs to reauthenticate
- None => Err(HttpError::Unauthenticated { redirect_to: None }),
+ None => Err(HttpError::Unauthenticated { redirect_to: Some(path.to_string()) }),
}
},
// Session cookies is missing: user needs to authenticate
- None => Err(HttpError::Unauthenticated { redirect_to: None }),
+ None => Err(HttpError::Unauthenticated { redirect_to: Some(path.to_string())}),
}
}
}