feat: add auth middleware chain with ctx resolver and cookie parsing

This commit is contained in:
2026-04-21 00:04:10 +03:00
parent 90c9b9d6ff
commit a120838cbc
10 changed files with 252 additions and 45 deletions

View File

@@ -3,9 +3,12 @@ use std::fmt;
use axum::{http::StatusCode, response::IntoResponse};
use tracing::info;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum LoftError {
LoginFail,
AuthFailNoAuthTokenCookie,
AuthFailTokenWrongFormat,
AuthFailCtxNotInRequestExt,
FileIdNotFound,
}
@@ -20,7 +23,10 @@ impl std::error::Error for LoftError {}
impl IntoResponse for LoftError {
fn into_response(self) -> axum::response::Response {
match self {
Self::LoginFail => {
Self::LoginFail
| Self::AuthFailNoAuthTokenCookie
| Self::AuthFailTokenWrongFormat
| Self::AuthFailCtxNotInRequestExt => {
info!("UNAUTHORIZED");
StatusCode::UNAUTHORIZED.into_response()
}