Skip to main content

edgequake_sdk/resources/
auth.rs

1//! Auth resource.
2
3use crate::client::EdgeQuakeClient;
4use crate::error::Result;
5use crate::types::auth::*;
6
7pub struct AuthResource<'a> {
8    pub(crate) client: &'a EdgeQuakeClient,
9}
10
11impl<'a> AuthResource<'a> {
12    /// `POST /api/v1/auth/login`
13    pub async fn login(&self, req: &LoginRequest) -> Result<TokenResponse> {
14        self.client.post("/api/v1/auth/login", Some(req)).await
15    }
16
17    /// `POST /api/v1/auth/refresh`
18    pub async fn refresh(&self, req: &RefreshRequest) -> Result<TokenResponse> {
19        self.client.post("/api/v1/auth/refresh", Some(req)).await
20    }
21
22    /// `GET /api/v1/auth/me`
23    pub async fn me(&self) -> Result<UserInfo> {
24        self.client.get("/api/v1/auth/me").await
25    }
26
27    /// `POST /api/v1/auth/logout`
28    pub async fn logout(&self) -> Result<()> {
29        self.client
30            .post_no_content::<()>("/api/v1/auth/logout", None)
31            .await
32    }
33}