diff --git a/Cargo.lock b/Cargo.lock index 7887a70..efa2514 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3761,6 +3761,7 @@ dependencies = [ "struct-patch", "thiserror 2.0.18", "tokio", + "tracing", "utoipa", ] diff --git a/frontend/src/components/auth/setup.rs b/frontend/src/components/auth/setup.rs index 10ba0af..832344a 100644 --- a/frontend/src/components/auth/setup.rs +++ b/frontend/src/components/auth/setup.rs @@ -41,7 +41,8 @@ pub fn Setup() -> impl IntoView { } Err(e) => { log::error!("Setup failed: {:?}", e); - error.1.set(Some("Kurulum sırasında bir hata oluştu".to_string())); + // Hatanın sadece mesaj kısmını almaya çalışalım, yoksa full struct basılabilir + error.1.set(Some(format!("Hata: {}", e))); loading.1.set(false); } } diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 0dd77ac..5606b4d 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -10,6 +10,7 @@ struct-patch = "0.5" rmp-serde = "1.3" bytes = "1" http = "1" +tracing = "0.1" # Leptos 0.8.7 leptos = { version = "0.8.15", features = ["nightly", "msgpack"] } diff --git a/shared/src/db.rs b/shared/src/db.rs index 541cab6..1b8b11e 100644 --- a/shared/src/db.rs +++ b/shared/src/db.rs @@ -28,8 +28,17 @@ impl Db { } async fn run_migrations(&self) -> Result<()> { - sqlx::migrate!("./migrations").run(&self.pool).await?; - Ok(()) + tracing::info!("Starting database migrations..."); + match sqlx::migrate!("./migrations").run(&self.pool).await { + Ok(_) => { + tracing::info!("Database migrations completed successfully."); + Ok(()) + } + Err(e) => { + tracing::error!("Database migration failed: {}", e); + Err(e.into()) + } + } } // --- User Operations --- diff --git a/shared/src/server_fns/auth.rs b/shared/src/server_fns/auth.rs index a7d7e07..fe6ee68 100644 --- a/shared/src/server_fns/auth.rs +++ b/shared/src/server_fns/auth.rs @@ -24,9 +24,19 @@ pub struct SetupStatus { pub async fn get_setup_status() -> Result { use crate::DbContext; - let db_context = use_context::().ok_or_else(|| ServerFnError::new("DB Context missing"))?; + tracing::info!("Checking setup status..."); + let db_context = use_context::().ok_or_else(|| { + tracing::error!("DB Context missing in GetSetupStatus"); + ServerFnError::new("DB Context missing") + })?; + let has_users = db_context.db.has_users().await - .map_err(|e| ServerFnError::new(format!("DB error: {}", e)))?; + .map_err(|e| { + tracing::error!("DB error in GetSetupStatus: {}", e); + ServerFnError::new(format!("DB error: {}", e)) + })?; + + tracing::info!("Setup status: completed={}", has_users); Ok(SetupStatus { completed: has_users, @@ -37,21 +47,33 @@ pub async fn get_setup_status() -> Result { pub async fn setup(username: String, password: String) -> Result<(), ServerFnError> { use crate::DbContext; - let db_context = use_context::().ok_or_else(|| ServerFnError::new("DB Context missing"))?; + tracing::info!("Attempting setup for user: {}", username); + let db_context = use_context::().ok_or_else(|| { + tracing::error!("DB Context missing in Setup"); + ServerFnError::new("DB Context missing") + })?; // Check if setup is already done let has_users = db_context.db.has_users().await.unwrap_or(false); if has_users { + tracing::warn!("Setup attempt blocked: Setup already completed"); return Err(ServerFnError::new("Setup already completed")); } // Hash password (low cost for MIPS) let password_hash = bcrypt::hash(&password, 6) - .map_err(|_| ServerFnError::new("Hashing error"))?; + .map_err(|e| { + tracing::error!("Hashing error: {}", e); + ServerFnError::new("Hashing error") + })?; db_context.db.create_user(&username, &password_hash).await - .map_err(|e| ServerFnError::new(format!("DB error: {}", e)))?; + .map_err(|e| { + tracing::error!("Failed to create user: {}", e); + ServerFnError::new(format!("DB error: {}", e)) + })?; + tracing::info!("Setup completed successfully for user: {}", username); Ok(()) } diff --git a/vibetorrent.db b/vibetorrent.db index 0927181..7ee7c11 100644 Binary files a/vibetorrent.db and b/vibetorrent.db differ diff --git a/vibetorrent.db-shm b/vibetorrent.db-shm new file mode 100644 index 0000000..3ae4e6c Binary files /dev/null and b/vibetorrent.db-shm differ diff --git a/vibetorrent.db-wal b/vibetorrent.db-wal new file mode 100644 index 0000000..4e49842 Binary files /dev/null and b/vibetorrent.db-wal differ