fix(auth): sync V2 CoreBridge authentication with legacy login
- Modified login/auto_login commands to also authenticate CoreBridge - Modified logout command to also logout from CoreBridge - Removed redundant v2_login call from LoginView.svelte frontend This ensures both legacy AppState.client and V2 CoreBridge.QbzCore.client are authenticated in sync, allowing V2 commands to work after login.
This commit is contained in:
1 parent
6b432586a7
commit
6778ef4ba6
2 files changed
+35
-1
No files matched your search
@@ -7,6 +7,7 @@ use crate::credentials;
|
|||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
use crate::api::error::ApiError;
|
use crate::api::error::ApiError;
|
||||||
use crate::config::SubscriptionStateState;
|
use crate::config::SubscriptionStateState;
|
||||||
|
use crate::core_bridge::CoreBridgeState;
|
||||||
use crate::offline_cache::OfflineCacheState;
|
use crate::offline_cache::OfflineCacheState;
|
||||||
|
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
@@ -77,6 +78,7 @@ pub async fn login(
|
|||||||
subscription_state: State<'_, SubscriptionStateState>,
|
subscription_state: State<'_, SubscriptionStateState>,
|
||||||
cache_state: State<'_, OfflineCacheState>,
|
cache_state: State<'_, OfflineCacheState>,
|
||||||
library_state: State<'_, crate::library::commands::LibraryState>,
|
library_state: State<'_, crate::library::commands::LibraryState>,
|
||||||
|
core_bridge: State<'_, CoreBridgeState>,
|
||||||
) -> Result<LoginResponse, String> {
|
) -> Result<LoginResponse, String> {
|
||||||
let client = state.client.read().await;
|
let client = state.client.read().await;
|
||||||
let now = now_unix_secs();
|
let now = now_unix_secs();
|
||||||
@@ -88,6 +90,15 @@ pub async fn login(
|
|||||||
let _ = store.mark_valid(now);
|
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 {
|
Ok(LoginResponse {
|
||||||
success: true,
|
success: true,
|
||||||
user_name: Some(session.display_name),
|
user_name: Some(session.display_name),
|
||||||
@@ -149,9 +160,20 @@ pub async fn init_client(state: State<'_, AppState>) -> Result<bool, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[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;
|
let client = state.client.read().await;
|
||||||
client.logout().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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,6 +222,7 @@ pub async fn auto_login(
|
|||||||
subscription_state: State<'_, SubscriptionStateState>,
|
subscription_state: State<'_, SubscriptionStateState>,
|
||||||
cache_state: State<'_, OfflineCacheState>,
|
cache_state: State<'_, OfflineCacheState>,
|
||||||
library_state: State<'_, crate::library::commands::LibraryState>,
|
library_state: State<'_, crate::library::commands::LibraryState>,
|
||||||
|
core_bridge: State<'_, CoreBridgeState>,
|
||||||
) -> Result<LoginResponse, String> {
|
) -> Result<LoginResponse, String> {
|
||||||
// Check for saved credentials
|
// Check for saved credentials
|
||||||
let creds = match credentials::load_qobuz_credentials() {
|
let creds = match credentials::load_qobuz_credentials() {
|
||||||
@@ -238,6 +261,15 @@ pub async fn auto_login(
|
|||||||
let _ = store.mark_valid(now);
|
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 {
|
Ok(LoginResponse {
|
||||||
success: true,
|
success: true,
|
||||||
user_name: Some(session.display_name),
|
user_name: Some(session.display_name),
|
||||||
|
|||||||
@@ -192,6 +192,8 @@
|
|||||||
console.log('Login response:', response);
|
console.log('Login response:', response);
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
// V2 CoreBridge is now authenticated automatically by the backend login command
|
||||||
|
|
||||||
// Save credentials if "Remember me" is checked
|
// Save credentials if "Remember me" is checked
|
||||||
if (rememberMe) {
|
if (rememberMe) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in new issue
Block a user