Use middleware instead of manual auth checks

This commit is contained in:
Andras Schmelczer 2025-04-04 21:47:19 +01:00
parent fb71460fc3
commit b5e528d8b8
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
8 changed files with 86 additions and 135 deletions

View file

@ -1,14 +1,10 @@
use anyhow::Context as _;
use axum::extract::{Path, State};
use axum_extra::{
TypedHeader,
headers::{Authorization, authorization::Bearer},
};
use axum_jsonschema::Json;
use schemars::JsonSchema;
use serde::Deserialize;
use super::{auth::auth, requests::DeleteDocumentVersion};
use super::requests::DeleteDocumentVersion;
use crate::{
app_state::{
AppState,
@ -29,7 +25,6 @@ pub struct DeleteDocumentPathParams {
#[axum::debug_handler]
pub async fn delete_document(
TypedHeader(auth_header): TypedHeader<Authorization<Bearer>>,
Path(DeleteDocumentPathParams {
vault_id,
document_id,
@ -37,8 +32,6 @@ pub async fn delete_document(
State(state): State<AppState>,
Json(request): Json<DeleteDocumentVersion>,
) -> Result<Json<DocumentVersionWithoutContent>, SyncServerError> {
auth(&state, auth_header.token(), &vault_id)?;
let mut transaction = state
.database
.create_write_transaction(&vault_id)