registration auth services added

This commit is contained in:
filipriec
2025-04-10 21:00:41 +02:00
parent a9089bc2ff
commit dfb6f5b375

View File

@@ -2,7 +2,8 @@
use tonic::transport::Channel;
use common::proto::multieko2::auth::{
auth_service_client::AuthServiceClient,
LoginRequest, LoginResponse
LoginRequest, LoginResponse,
RegisterRequest, AuthResponse,
};
pub struct AuthClient {
@@ -15,9 +16,28 @@ impl AuthClient {
Ok(Self { client })
}
/// Login user via gRPC.
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.client.login(request).await?.into_inner();
Ok(response)
}
/// Registers a new user via gRPC.
pub async fn register(
&mut self,
username: String,
email: String,
password: Option<String>, // Use Option for optional fields
password_confirmation: Option<String>, // Use Option for optional fields
) -> Result<AuthResponse, Box<dyn std::error::Error>> {
let request = tonic::Request::new(RegisterRequest {
username,
email,
password: password.unwrap_or_default(), // Send empty string if None
password_confirmation: password_confirmation.unwrap_or_default(), // Send empty string if None
});
let response = self.client.register(request).await?.into_inner();
Ok(response)
}
}