~whbboyd/russet

cf4ac011bfaf6c8cd1797b6e66a08daad9397f83 — Will Boyd 4 months ago 2b89574
Redirect to previous path on auth error
1 files changed, 6 insertions(+), 2 deletions(-)

M src/http/session.rs
M src/http/session.rs => src/http/session.rs +6 -2
@@ 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())}),
		}
	}
}