use reqwest::Method;
use serde::Deserialize;
use crate::client::Client;
use crate::error::Error;
use crate::http::RequestSpec;
pub struct AuthResource {
pub(crate) client: Client,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct AuthProvider {
#[serde(default)]
pub provider: Option<String>,
#[serde(default)]
pub email: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProfilePicture {
#[serde(default)]
pub url: Option<String>,
#[serde(default)]
pub source: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct User {
pub id: String,
#[serde(default)]
pub email: Option<String>,
pub email_verified: bool,
#[serde(default)]
pub user_name: Option<String>,
pub plan: String,
pub password_set: bool,
#[serde(default)]
pub auth_providers: Vec<AuthProvider>,
#[serde(default)]
pub pfp: Option<ProfilePicture>,
}
#[derive(Deserialize)]
struct MeWire {
user: User,
}
impl AuthResource {
pub async fn me(&self) -> Result<User, Error> {
let wire: MeWire = self
.client
.transport
.execute(RequestSpec::new(Method::GET, "/auth/me"))
.await?;
Ok(wire.user)
}
}