feat: use custom middleware for authorization
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful

This commit is contained in:
Radical 2025-07-20 14:12:57 +02:00
parent dada230e08
commit 1ad88725bd
24 changed files with 157 additions and 365 deletions

View file

@ -1,19 +1,13 @@
use std::sync::Arc;
use axum::{
Json,
extract::{Path, State},
http::StatusCode,
response::IntoResponse,
};
use axum_extra::{
TypedHeader,
headers::{Authorization, authorization::Bearer},
extract::{Path, State}, http::StatusCode, response::IntoResponse, Extension, Json
};
use uuid::Uuid;
use crate::{
AppState,
api::v1::auth::check_access_token,
api::v1::auth::CurrentUser,
error::Error,
objects::{Guild, Invite, Member},
utils::global_checks,
@ -35,14 +29,12 @@ pub async fn get(
pub async fn join(
State(app_state): State<Arc<AppState>>,
Path(invite_id): Path<String>,
TypedHeader(auth): TypedHeader<Authorization<Bearer>>,
Extension(CurrentUser(uuid)): Extension<CurrentUser<Uuid>>,
) -> Result<impl IntoResponse, Error> {
let mut conn = app_state.pool.get().await?;
let uuid = check_access_token(auth.token(), &mut conn).await?;
global_checks(&app_state, uuid).await?;
let mut conn = app_state.pool.get().await?;
let invite = Invite::fetch_one(&mut conn, invite_id).await?;
let guild = Guild::fetch_one(&mut conn, invite.guild_uuid).await?;