24 lines
749 B
Rust
24 lines
749 B
Rust
// src/services/auth.rs
|
|
use tonic::transport::Channel;
|
|
use common::proto::multieko2::auth::{
|
|
auth_service_client::AuthServiceClient,
|
|
LoginRequest, LoginResponse
|
|
};
|
|
|
|
pub struct AuthClient {
|
|
client: AuthServiceClient<Channel>,
|
|
}
|
|
|
|
impl AuthClient {
|
|
pub async fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
|
let client = AuthServiceClient::connect("http://[::1]:50051").await?;
|
|
Ok(Self { client })
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|