Skip to main content

proto_blue_api/generated/com/atproto/server/
getSession.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: com.atproto.server.getSession
3
4use serde::{Deserialize, Serialize};
5
6/// Get information about the current auth session. Requires auth.
7/// XRPC Query: com.atproto.server.getSession
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Output {
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub active: Option<bool>,
13    pub did: String,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub did_doc: Option<serde_json::Value>,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub email: Option<String>,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub email_auth_factor: Option<bool>,
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub email_confirmed: Option<bool>,
22    pub handle: String,
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub status: Option<String>,
25}
26
27/// Errors a `call()` on this method can return.
28#[derive(Debug, thiserror::Error)]
29pub enum CallError {
30    #[error("{0}")]
31    Xrpc(proto_blue_xrpc::XrpcError),
32    #[error(transparent)]
33    Transport(#[from] proto_blue_xrpc::Error),
34    #[error(transparent)]
35    Json(#[from] serde_json::Error),
36}
37
38fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
39    CallError::Xrpc(err)
40}
41
42/// Execute the query.
43pub async fn call(
44    client: &proto_blue_xrpc::XrpcClient,
45    opts: Option<&proto_blue_xrpc::CallOptions>,
46) -> Result<Output, CallError> {
47    let response = match client.query("com.atproto.server.getSession", None, opts).await {
48        Ok(r) => r,
49        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
50        Err(e) => return Err(CallError::Transport(e)),
51    };
52    Ok(serde_json::from_value(response.data)?)
53}
54
55/// Register a typed handler for this method on an [`XrpcServer`].
56#[cfg(feature = "server")]
57pub fn register<F, Fut>(
58server: proto_blue_xrpc::XrpcServer,
59handler: F,
60) -> proto_blue_xrpc::XrpcServer
61where
62    F: Fn(proto_blue_xrpc::HandlerContext) -> Fut + Send + Sync + 'static,
63    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
64{
65    let handler = std::sync::Arc::new(handler);
66    server.query("com.atproto.server.getSession", move |ctx| {
67        let handler = handler.clone();
68        async move {
69            let out = handler(ctx).await?;
70            let value = serde_json::to_value(&out)
71                .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
72            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
73        }
74    })
75}
76