BLOG-86 Checking authentication before uploading image #101

Merged
squid merged 5 commits from BLOG-86_image_can_only_be_uploaded_by_logged_in_user into main 2025-08-01 18:26:39 +08:00
2 changed files with 8 additions and 2 deletions
Showing only changes of commit eb7a3cf985 - Show all commits

View File

@ -32,7 +32,13 @@ pub async fn auth_middleware(
next.call(req).await next.call(req).await
} }
pub struct UserId(pub i32); pub struct UserId(i32);
impl UserId {
pub fn get(&self) -> i32 {
self.0
}
}
impl FromRequest for UserId { impl FromRequest for UserId {
type Error = Error; type Error = Error;

View File

@ -102,5 +102,5 @@ async fn logout_handler(session: Session) -> impl Responder {
} }
async fn get_logged_in_user_handler(user_id: UserId) -> impl Responder { async fn get_logged_in_user_handler(user_id: UserId) -> impl Responder {
HttpResponse::Ok().body(format!("Logged in user ID: {}", user_id.0)) HttpResponse::Ok().body(format!("Logged in user ID: {}", user_id.get()))
} }