Added Auth Context

implement login client code (todo: server login)
Added aboa icon
This commit is contained in:
2025-05-03 23:52:51 -04:00
parent e223612a08
commit d0cc8be566
21 changed files with 135 additions and 48 deletions

View File

@@ -1,32 +1,42 @@
use std::sync::RwLock;
use aoba::aoba_rpc_client::AobaRpcClient;
use aoba::{aoba_rpc_client::AobaRpcClient, auth_rpc_client::AuthRpcClient};
use tonic_web_wasm_client::Client;
pub mod aoba {
tonic::include_proto!("aoba");
tonic::include_proto!("aoba.auth");
}
const HOST: &'static str = "http://localhost:5164";
static RPC_CLIENT: RpcConnection = RpcConnection {
client: RwLock::new(None),
aoba: RwLock::new(None),
auth: RwLock::new(None),
};
#[derive(Default)]
pub struct RpcConnection {
client: RwLock<Option<AobaRpcClient<Client>>>,
aoba: RwLock<Option<AobaRpcClient<Client>>>,
auth: RwLock<Option<AuthRpcClient<Client>>>,
}
impl RpcConnection {
pub fn get_client(&self) -> AobaRpcClient<Client> {
self.ensure_client();
return self.client.read().unwrap().clone().unwrap();
return self.aoba.read().unwrap().clone().unwrap();
}
pub fn get_auth_client(&self) -> AuthRpcClient<Client> {
self.ensure_client();
return self.auth.read().unwrap().clone().unwrap();
}
fn ensure_client(&self) {
if self.client.read().unwrap().is_none() {
let wasm_client = Client::new("http://localhost:5164".into());
let c = AobaRpcClient::new(wasm_client);
*self.client.write().unwrap() = Some(c);
if self.aoba.read().unwrap().is_none() {
let wasm_client = Client::new(HOST.into());
*self.aoba.write().unwrap() = Some(AobaRpcClient::new(wasm_client.clone()));
*self.auth.write().unwrap() = Some(AuthRpcClient::new(wasm_client.clone()));
}
}
}
@@ -34,3 +44,7 @@ impl RpcConnection {
pub fn get_rpc_client() -> AobaRpcClient<Client> {
return RPC_CLIENT.get_client();
}
pub fn get_auth_rpc_client() -> AuthRpcClient<Client> {
return RPC_CLIENT.get_auth_client();
}