registration auth services added
This commit is contained in:
@@ -2,7 +2,8 @@
|
|||||||
use tonic::transport::Channel;
|
use tonic::transport::Channel;
|
||||||
use common::proto::multieko2::auth::{
|
use common::proto::multieko2::auth::{
|
||||||
auth_service_client::AuthServiceClient,
|
auth_service_client::AuthServiceClient,
|
||||||
LoginRequest, LoginResponse
|
LoginRequest, LoginResponse,
|
||||||
|
RegisterRequest, AuthResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct AuthClient {
|
pub struct AuthClient {
|
||||||
@@ -15,9 +16,28 @@ impl AuthClient {
|
|||||||
Ok(Self { client })
|
Ok(Self { client })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Login user via gRPC.
|
||||||
pub async fn login(&mut self, identifier: String, password: String) -> Result<LoginResponse, Box<dyn std::error::Error>> {
|
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 request = tonic::Request::new(LoginRequest { identifier, password });
|
||||||
let response = self.client.login(request).await?.into_inner();
|
let response = self.client.login(request).await?.into_inner();
|
||||||
Ok(response)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user