From 1ba46134e4457b43e5161447bc2b6db240ae442f Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Wed, 29 Nov 2023 11:40:38 -0800 Subject: [PATCH] client_authenticated fix + type export --- CHANGELOG.md | 3 +++ crates/bonsaidb-client/src/builder.rs | 5 +++++ crates/bonsaidb-client/src/lib.rs | 4 +++- crates/bonsaidb-server/src/dispatch.rs | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2df95e96d..a92fc92aa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `bonsaidb::client::Error::Core`'s `Display` no longer just prints "unexpected disconnection". Instead, the inner error's `Display` is now displayed. +- `bonsaidb::client::Async`/`Blocking` are now exposed. These types are used + when building a client. +- `bonsaidb::server::Backend::client_authenticated` is now invoked. ## v0.5.0 diff --git a/crates/bonsaidb-client/src/builder.rs b/crates/bonsaidb-client/src/builder.rs index e79c5247b8..d29834cb44 100644 --- a/crates/bonsaidb-client/src/builder.rs +++ b/crates/bonsaidb-client/src/builder.rs @@ -17,7 +17,12 @@ use crate::client::{AnyApiCallback, ApiCallback}; use crate::BlockingClient; use crate::{AsyncClient, Error}; +/// A type marker for [`Builder`] indicating the returned client should be an +/// [`AsyncClient`]. pub struct Async; + +/// A type marker for [`Builder`] indicating the returned client should be an +/// [`BlockingClient`]. #[cfg(not(target_arch = "wasm32"))] pub struct Blocking; diff --git a/crates/bonsaidb-client/src/lib.rs b/crates/bonsaidb-client/src/lib.rs index 40a36dbb33..4c96388b32 100644 --- a/crates/bonsaidb-client/src/lib.rs +++ b/crates/bonsaidb-client/src/lib.rs @@ -24,7 +24,9 @@ mod error; #[cfg(not(target_arch = "wasm32"))] pub use fabruic; -pub use self::builder::Builder; +#[cfg(not(target_arch = "wasm32"))] +pub use self::builder::Blocking; +pub use self::builder::{Async, Builder}; pub use self::client::{ApiCallback, AsyncClient, AsyncRemoteDatabase, AsyncRemoteSubscriber}; #[cfg(not(target_arch = "wasm32"))] pub use self::client::{BlockingClient, BlockingRemoteDatabase, BlockingRemoteSubscriber}; diff --git a/crates/bonsaidb-server/src/dispatch.rs b/crates/bonsaidb-server/src/dispatch.rs index cdf1a6cbb4..fdfddb22d8 100644 --- a/crates/bonsaidb-server/src/dispatch.rs +++ b/crates/bonsaidb-server/src/dispatch.rs @@ -200,6 +200,15 @@ impl Handler for ServerDispatcher { session.client.logged_in_as(new_session.clone()); + if let Err(err) = session + .server + .backend() + .client_authenticated(session.client.clone(), &new_session, session.server) + .await + { + log::error!("[server] Error in `client_authenticated`: {err:?}"); + } + Ok(new_session) } } @@ -215,6 +224,15 @@ impl Handler for ServerDispatcher { session.client.logged_in_as(new_session.clone()); + if let Err(err) = session + .server + .backend() + .client_authenticated(session.client.clone(), &new_session, session.server) + .await + { + log::error!("[server] Error in `client_authenticated`: {err:?}"); + } + Ok(new_session) } }