Include require auth middleware and login route
This commit is contained in:
@@ -11,7 +11,10 @@ use migration::sea_orm::DatabaseConnection;
|
||||
use crate::{
|
||||
middlewares,
|
||||
services::{
|
||||
auth::{authentication::AuthenticationService, user::UserService},
|
||||
auth::{
|
||||
authentication::{AuthenticationService, strategies::password::PasswordStrategy},
|
||||
user::UserService,
|
||||
},
|
||||
settings::SettingsStore,
|
||||
},
|
||||
};
|
||||
@@ -28,25 +31,35 @@ pub struct AppState {
|
||||
|
||||
pub type ServiceState<T> = Arc<T>;
|
||||
|
||||
pub struct AppService {
|
||||
#[allow(dead_code)] // TODO: remove when used
|
||||
pub settings: ServiceState<dyn SettingsStore>,
|
||||
#[allow(dead_code)] // TODO: remove when used
|
||||
pub struct AuthStrategy {
|
||||
pub password: ServiceState<PasswordStrategy>,
|
||||
}
|
||||
|
||||
pub struct AuthState {
|
||||
pub strategy: AuthStrategy,
|
||||
pub authentication: ServiceState<dyn AuthenticationService>,
|
||||
#[allow(dead_code)] // TODO: remove when used
|
||||
pub user: ServiceState<dyn UserService>,
|
||||
}
|
||||
|
||||
pub struct AppService {
|
||||
// #[allow(dead_code)] // TODO: remove when used
|
||||
pub settings: ServiceState<dyn SettingsStore>,
|
||||
pub auth_state: AuthState,
|
||||
// #[allow(dead_code)] // TODO: remove when used
|
||||
pub user: ServiceState<dyn UserService>,
|
||||
}
|
||||
|
||||
pub fn get_root_router(state: impl Into<Arc<AppState>>) -> Router {
|
||||
let mut router = Router::new();
|
||||
let state = state.into();
|
||||
|
||||
router = router
|
||||
.nest("/api", api::get_api_router())
|
||||
.nest("/api", api::get_api_router(state.clone()))
|
||||
.merge(view::get_view_router());
|
||||
|
||||
router = middlewares::apply_root_middleware(router);
|
||||
router = middlewares::apply_root_middleware(router, state.clone());
|
||||
|
||||
router = router.layer(Extension(state.into()));
|
||||
router = router.layer(Extension(state.clone()));
|
||||
|
||||
router
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user