surrealdb/api/method/
authenticate.rs

1use crate::api::conn::Method;
2use crate::api::conn::Param;
3use crate::api::method::OnceLockExt;
4use crate::api::opt::auth::Jwt;
5use crate::api::Connection;
6use crate::api::Result;
7use crate::Surreal;
8use std::borrow::Cow;
9use std::future::Future;
10use std::future::IntoFuture;
11use std::pin::Pin;
12
13/// An authentication future
14#[derive(Debug)]
15#[must_use = "futures do nothing unless you `.await` or poll them"]
16pub struct Authenticate<'r, C: Connection> {
17	pub(super) client: Cow<'r, Surreal<C>>,
18	pub(super) token: Jwt,
19}
20
21impl<'r, Client> IntoFuture for Authenticate<'r, Client>
22where
23	Client: Connection,
24{
25	type Output = Result<()>;
26	type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send + Sync + 'r>>;
27
28	fn into_future(self) -> Self::IntoFuture {
29		Box::pin(async move {
30			let router = self.client.router.extract()?;
31			let mut conn = Client::new(Method::Authenticate);
32			conn.execute_unit(router, Param::new(vec![self.token.0.into()])).await
33		})
34	}
35}