diff --git a/src-tauri/src/commands/auth.rs b/src-tauri/src/commands/auth.rs index 5b6b2eaf6..f0eaafe6f 100644 --- a/src-tauri/src/commands/auth.rs +++ b/src-tauri/src/commands/auth.rs @@ -7,6 +7,7 @@ use crate::credentials; use crate::AppState; use crate::api::error::ApiError; use crate::config::SubscriptionStateState; +use crate::core_bridge::CoreBridgeState; use crate::offline_cache::OfflineCacheState; #[derive(serde::Serialize)] @@ -77,6 +78,7 @@ pub async fn login( subscription_state: State<'_, SubscriptionStateState>, cache_state: State<'_, OfflineCacheState>, library_state: State<'_, crate::library::commands::LibraryState>, + core_bridge: State<'_, CoreBridgeState>, ) -> Result { let client = state.client.read().await; let now = now_unix_secs(); @@ -88,6 +90,15 @@ pub async fn login( let _ = store.mark_valid(now); } } + + // Also authenticate V2 CoreBridge client for the new architecture + let bridge = core_bridge.get().await; + if let Err(e) = bridge.login(&email, &password).await { + log::warn!("[Auth] V2 CoreBridge login failed (non-blocking): {}", e); + } else { + log::info!("[Auth] V2 CoreBridge authenticated successfully"); + } + Ok(LoginResponse { success: true, user_name: Some(session.display_name), @@ -149,9 +160,20 @@ pub async fn init_client(state: State<'_, AppState>) -> Result { } #[tauri::command] -pub async fn logout(state: State<'_, AppState>) -> Result<(), String> { +pub async fn logout( + state: State<'_, AppState>, + core_bridge: State<'_, CoreBridgeState>, +) -> Result<(), String> { + // Logout from legacy client let client = state.client.read().await; client.logout().await; + + // Also logout from V2 CoreBridge + let bridge = core_bridge.get().await; + if let Err(e) = bridge.logout().await { + log::warn!("[Auth] V2 CoreBridge logout failed: {}", e); + } + Ok(()) } @@ -200,6 +222,7 @@ pub async fn auto_login( subscription_state: State<'_, SubscriptionStateState>, cache_state: State<'_, OfflineCacheState>, library_state: State<'_, crate::library::commands::LibraryState>, + core_bridge: State<'_, CoreBridgeState>, ) -> Result { // Check for saved credentials let creds = match credentials::load_qobuz_credentials() { @@ -238,6 +261,15 @@ pub async fn auto_login( let _ = store.mark_valid(now); } } + + // Also authenticate V2 CoreBridge client for the new architecture + let bridge = core_bridge.get().await; + if let Err(e) = bridge.login(&creds.email, &creds.password).await { + log::warn!("[Auth/Auto] V2 CoreBridge login failed (non-blocking): {}", e); + } else { + log::info!("[Auth/Auto] V2 CoreBridge authenticated successfully"); + } + Ok(LoginResponse { success: true, user_name: Some(session.display_name), diff --git a/src/lib/components/views/LoginView.svelte b/src/lib/components/views/LoginView.svelte index 3ca1d9877..58d51a8a6 100644 --- a/src/lib/components/views/LoginView.svelte +++ b/src/lib/components/views/LoginView.svelte @@ -192,6 +192,8 @@ console.log('Login response:', response); if (response.success) { + // V2 CoreBridge is now authenticated automatically by the backend login command + // Save credentials if "Remember me" is checked if (rememberMe) { try {