login gRPC

This commit is contained in:
filipriec
2025-03-31 16:16:07 +02:00
parent 7f5b671084
commit e2c326bf1e
3 changed files with 28 additions and 7 deletions

View File

@@ -1,18 +1,35 @@
// src/tui/functions/common/login.rs
use crate::services::auth::AuthClient;
use crate::state::pages::auth::AuthState;
use crate::services::grpc_client::GrpcClient;
pub async fn save(
auth_state: &mut AuthState,
grpc_client: &mut GrpcClient,
auth_client: &mut AuthClient,
) -> Result<String, Box<dyn std::error::Error>> {
// Implement your login-specific save logic here
Ok("Login credentials saved - not implemented yet".to_string())
let identifier = auth_state.username.clone();
let password = auth_state.password.clone();
match auth_client.login(identifier, password).await {
Ok(response) => {
auth_state.auth_token = Some(response.access_token);
auth_state.user_id = Some(response.user_id);
auth_state.role = Some(response.role);
auth_state.error_message = None;
Ok("Login successful!".to_string())
}
Err(e) => {
let error_message = format!("Login failed: {}", e);
auth_state.error_message = Some(error_message.clone());
Ok(error_message)
}
}
}
pub async fn cancel(
auth_state: &mut AuthState,
) -> String {
"Login credentials canceled - not implemented yet".to_string()
auth_state.username.clear();
auth_state.password.clear();
auth_state.error_message = None;
"Login canceled".to_string()
}