feat: implement authentication module with JWT support and user management
This commit is contained in:
@@ -12,7 +12,10 @@ use crate::{
|
||||
configs::{ProgramSettings, get_program_settings, logging::LoggingSettings},
|
||||
log,
|
||||
routes::{self, AppService, AppState},
|
||||
services::settings::SettingsService,
|
||||
services::{
|
||||
auth::{authentication::AuthenticationServiceImpl, user::UserServiceImpl},
|
||||
settings::SettingsService,
|
||||
},
|
||||
tasks,
|
||||
};
|
||||
|
||||
@@ -58,6 +61,9 @@ pub async fn start_server() {
|
||||
|
||||
tasks::startup::run_startup_tasks(&settings)
|
||||
.await
|
||||
.inspect_err(|err| {
|
||||
tracing::error!("Failed to run startup tasks: {}", err);
|
||||
})
|
||||
.expect("Failed to run startup tasks");
|
||||
|
||||
// setup database connection pool
|
||||
@@ -78,7 +84,7 @@ pub async fn start_server() {
|
||||
|
||||
// build the axum app and run the server...
|
||||
info!("Starting application...");
|
||||
let app: Router = routes::get_root_router(Arc::new(get_app_state(&db_connection)));
|
||||
let app: Router = routes::get_root_router(Arc::new(get_app_state(&db_connection, &settings)));
|
||||
|
||||
let address = format!("{}:{}", settings.server.address, settings.server.port);
|
||||
info!("Starting server at http://{}", address);
|
||||
@@ -115,11 +121,18 @@ fn get_global_tracing_subscriber_builder(
|
||||
}
|
||||
}
|
||||
|
||||
fn get_app_state(db_connection: &Arc<sea_orm::DatabaseConnection>) -> AppState {
|
||||
fn get_app_state(
|
||||
db_connection: &Arc<sea_orm::DatabaseConnection>,
|
||||
settings: &ProgramSettings,
|
||||
) -> AppState {
|
||||
AppState {
|
||||
database_connection: db_connection.clone(),
|
||||
service: Arc::new(AppService {
|
||||
settings: Arc::new(SettingsService::new(db_connection.clone())),
|
||||
authentication: Arc::new(AuthenticationServiceImpl::new(
|
||||
settings.auth.jwt_secret.clone(),
|
||||
)),
|
||||
user: Arc::new(UserServiceImpl::new(db_connection.clone())),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user