From dfb6f5b375bfb91a71900ca20d95c1920b5e6dd1 Mon Sep 17 00:00:00 2001 From: filipriec Date: Thu, 10 Apr 2025 21:00:41 +0200 Subject: [PATCH] registration auth services added --- client/src/services/auth.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/client/src/services/auth.rs b/client/src/services/auth.rs index 01138d2..fdcb7b3 100644 --- a/client/src/services/auth.rs +++ b/client/src/services/auth.rs @@ -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> { 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, // Use Option for optional fields + password_confirmation: Option, // Use Option for optional fields + ) -> Result> { + 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) + } }