feat: use custom middleware for authorization
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
This commit is contained in:
parent
dada230e08
commit
1ad88725bd
24 changed files with 157 additions and 365 deletions
|
@ -2,9 +2,9 @@
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::{routing::get, Router};
|
||||
use axum::{middleware::from_fn_with_state, routing::get, Router};
|
||||
|
||||
use crate::AppState;
|
||||
use crate::{api::v1::auth::CurrentUser, AppState};
|
||||
|
||||
mod auth;
|
||||
mod channels;
|
||||
|
@ -14,13 +14,17 @@ mod me;
|
|||
mod stats;
|
||||
mod users;
|
||||
|
||||
pub fn router() -> Router<Arc<AppState>> {
|
||||
Router::new()
|
||||
.route("/stats", get(stats::res))
|
||||
.nest("/auth", auth::router())
|
||||
pub fn router(app_state: Arc<AppState>) -> Router<Arc<AppState>> {
|
||||
let router_with_auth = Router::new()
|
||||
.nest("/users", users::router())
|
||||
.nest("/channels", channels::router())
|
||||
.nest("/guilds", guilds::router())
|
||||
.nest("/invites", invites::router())
|
||||
.nest("/me", me::router())
|
||||
.layer(from_fn_with_state(app_state.clone(), CurrentUser::check_auth_layer));
|
||||
|
||||
Router::new()
|
||||
.route("/stats", get(stats::res))
|
||||
.nest("/auth", auth::router(app_state))
|
||||
.merge(router_with_auth)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue