Add auth service client and auth state fields

This commit is contained in:
filipriec
2025-03-30 21:44:45 +02:00
parent e19b30f4f4
commit 2ed2419f9e
2 changed files with 19 additions and 0 deletions

View File

@@ -9,6 +9,9 @@ pub struct AuthState {
pub error_message: Option<String>,
pub current_field: usize,
pub current_cursor_pos: usize,
pub auth_token: Option<String>,
pub user_id: Option<String>,
pub role: Option<String>,
}
impl AuthState {
@@ -20,6 +23,9 @@ impl AuthState {
error_message: None,
current_field: 0,
current_cursor_pos: 0,
auth_token: None,
user_id: None,
role: None,
}
}
}

View File

@@ -10,11 +10,16 @@ use common::proto::multieko2::table_definition::{
table_definition_client::TableDefinitionClient,
ProfileTreeResponse
};
use common::proto::multieko2::auth::{
auth_service_client::AuthServiceClient,
LoginRequest, LoginResponse
};
pub struct GrpcClient {
adresar_client: AdresarClient<Channel>,
table_structure_client: TableStructureServiceClient<Channel>,
table_definition_client: TableDefinitionClient<Channel>,
auth_client: AuthServiceClient<Channel>,
}
impl GrpcClient {
@@ -22,11 +27,13 @@ impl GrpcClient {
let adresar_client = AdresarClient::connect("http://[::1]:50051").await?;
let table_structure_client = TableStructureServiceClient::connect("http://[::1]:50051").await?;
let table_definition_client = TableDefinitionClient::connect("http://[::1]:50051").await?;
let auth_client = AuthServiceClient::connect("http://[::1]:50051").await?;
Ok(Self {
adresar_client,
table_structure_client,
table_definition_client,
auth_client,
})
}
@@ -65,4 +72,10 @@ impl GrpcClient {
let response = self.table_definition_client.get_profile_tree(request).await?;
Ok(response.into_inner())
}
pub async fn login(&mut self, identifier: String, password: String) -> Result<LoginResponse, Box<dyn std::error::Error>> {
let request = tonic::Request::new(LoginRequest { identifier, password });
let response = self.auth_client.login(request).await?.into_inner();
Ok(response)
}
}