polyester/services/
auth.rs1use super::ServiceContext;
2use super::profile::ProfileService;
3use super::unary;
4use crate::codecs::decode::me_from_proto;
5use crate::connect::auth::v1::AuthServiceClient;
6use crate::errors::Result;
7use crate::models::MeResult;
8use crate::proto::auth::v1::MeRequest;
9
10#[derive(Clone)]
11pub struct AuthService {
12 ctx: ServiceContext,
13 pub profile: ProfileService,
14}
15
16impl AuthService {
17 pub fn new(ctx: ServiceContext) -> Self {
18 Self {
19 profile: ProfileService::new(ctx.clone()),
20 ctx,
21 }
22 }
23
24 pub async fn me(&self) -> Result<MeResult> {
25 let client = AuthServiceClient::new(
26 self.ctx.factory.transport(),
27 self.ctx.factory.connect_config(),
28 );
29 let req = MeRequest::default();
30 let resp = unary::await_auth(
31 &self.ctx.factory,
32 "/auth.v1.AuthService/Me",
33 req,
34 |req, opts| client.me_with_options(req, opts),
35 )
36 .await?
37 .into_owned();
38 Ok(me_from_proto(&resp))
39 }
40}