fix(v2): make CoreBridge auth blocking per ADR
- auto_login now fails if V2 CoreBridge auth fails - runtime_bootstrap now fails if V2 CoreBridge auth fails - Add V2AuthFailed and V2NotInitialized runtime error variants - Consistent with login command which was already blocking
This commit is contained in:
1 parent
8a844612ff
commit
854088c3de
3 files changed
+36
-9
No files matched your search
@@ -296,16 +296,34 @@ pub async fn auto_login(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also authenticate V2 CoreBridge client for the new architecture
|
// V2 CoreBridge authentication - REQUIRED per ADR Runtime Session Contract
|
||||||
// Use try_get() to gracefully handle case where CoreBridge init is still in progress
|
// If V2 auth fails, return typed failure and do not report full success
|
||||||
if let Some(bridge) = core_bridge.try_get().await {
|
if let Some(bridge) = core_bridge.try_get().await {
|
||||||
if let Err(e) = bridge.login(&creds.email, &creds.password).await {
|
if let Err(e) = bridge.login(&creds.email, &creds.password).await {
|
||||||
log::warn!("[Auth/Auto] V2 CoreBridge login failed (non-blocking): {}", e);
|
log::error!("[Auth/Auto] V2 CoreBridge login failed: {}", e);
|
||||||
} else {
|
// V2 auth failed - report failure per ADR
|
||||||
log::info!("[Auth/Auto] V2 CoreBridge authenticated successfully");
|
return Ok(LoginResponse {
|
||||||
|
success: false,
|
||||||
|
user_name: Some(session.display_name.clone()),
|
||||||
|
user_id: Some(session.user_id),
|
||||||
|
subscription: Some(session.subscription_label.clone()),
|
||||||
|
subscription_valid_until: session.subscription_valid_until.clone(),
|
||||||
|
error: Some(format!("V2 authentication failed: {}", e)),
|
||||||
|
error_code: Some("v2_auth_failed".to_string()),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
log::info!("[Auth/Auto] V2 CoreBridge authenticated successfully");
|
||||||
} else {
|
} else {
|
||||||
log::warn!("[Auth/Auto] V2 CoreBridge not yet initialized, skipping V2 auth");
|
log::error!("[Auth/Auto] V2 CoreBridge not initialized - cannot complete auth");
|
||||||
|
return Ok(LoginResponse {
|
||||||
|
success: false,
|
||||||
|
user_name: Some(session.display_name.clone()),
|
||||||
|
user_id: Some(session.user_id),
|
||||||
|
subscription: Some(session.subscription_label.clone()),
|
||||||
|
subscription_valid_until: session.subscription_valid_until.clone(),
|
||||||
|
error: Some("V2 CoreBridge not initialized".to_string()),
|
||||||
|
error_code: Some("v2_not_initialized".to_string()),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(LoginResponse {
|
Ok(LoginResponse {
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ pub async fn runtime_bootstrap(
|
|||||||
// For now, we just mark the user_id and let the frontend handle it
|
// For now, we just mark the user_id and let the frontend handle it
|
||||||
// In a full implementation, we'd activate here directly
|
// In a full implementation, we'd activate here directly
|
||||||
|
|
||||||
// Step 4: Authenticate CoreBridge/V2
|
// Step 4: Authenticate CoreBridge/V2 - REQUIRED per ADR
|
||||||
if let Some(bridge) = core_bridge.try_get().await {
|
if let Some(bridge) = core_bridge.try_get().await {
|
||||||
match bridge.login(&creds.email, &creds.password).await {
|
match bridge.login(&creds.email, &creds.password).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
@@ -192,11 +192,14 @@ pub async fn runtime_bootstrap(
|
|||||||
let _ = app.emit("runtime:event", RuntimeEvent::CoreBridgeAuthFailed {
|
let _ = app.emit("runtime:event", RuntimeEvent::CoreBridgeAuthFailed {
|
||||||
error: e.to_string(),
|
error: e.to_string(),
|
||||||
});
|
});
|
||||||
// Don't fail bootstrap - V2 auth failure is recoverable
|
manager.set_bootstrap_in_progress(false).await;
|
||||||
|
return Err(RuntimeError::V2AuthFailed(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log::warn!("[Runtime] CoreBridge not yet initialized, V2 auth deferred");
|
log::error!("[Runtime] CoreBridge not initialized - cannot complete bootstrap");
|
||||||
|
manager.set_bootstrap_in_progress(false).await;
|
||||||
|
return Err(RuntimeError::V2NotInitialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|||||||
@@ -100,6 +100,10 @@ pub enum RuntimeError {
|
|||||||
InvalidUserId,
|
InvalidUserId,
|
||||||
/// Bootstrap already in progress
|
/// Bootstrap already in progress
|
||||||
BootstrapInProgress,
|
BootstrapInProgress,
|
||||||
|
/// V2 CoreBridge authentication failed
|
||||||
|
V2AuthFailed(String),
|
||||||
|
/// V2 CoreBridge not initialized
|
||||||
|
V2NotInitialized,
|
||||||
/// Internal error
|
/// Internal error
|
||||||
Internal(String),
|
Internal(String),
|
||||||
}
|
}
|
||||||
@@ -114,6 +118,8 @@ impl std::fmt::Display for RuntimeError {
|
|||||||
Self::RuntimeDegraded(reason) => write!(f, "Runtime degraded: {:?}", reason),
|
Self::RuntimeDegraded(reason) => write!(f, "Runtime degraded: {:?}", reason),
|
||||||
Self::InvalidUserId => write!(f, "Invalid user ID"),
|
Self::InvalidUserId => write!(f, "Invalid user ID"),
|
||||||
Self::BootstrapInProgress => write!(f, "Bootstrap already in progress"),
|
Self::BootstrapInProgress => write!(f, "Bootstrap already in progress"),
|
||||||
|
Self::V2AuthFailed(msg) => write!(f, "V2 authentication failed: {}", msg),
|
||||||
|
Self::V2NotInitialized => write!(f, "V2 CoreBridge not initialized"),
|
||||||
Self::Internal(msg) => write!(f, "Internal error: {}", msg),
|
Self::Internal(msg) => write!(f, "Internal error: {}", msg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user