24 lines
630 B
Rust
24 lines
630 B
Rust
use crate::extractors::client_auth::APIClientAuth;
|
|
use crate::server::HttpResult;
|
|
use actix_web::HttpResponse;
|
|
use ruma::api::client::account;
|
|
use ruma::DeviceId;
|
|
|
|
#[derive(serde::Serialize)]
|
|
struct WhoAmIResponse {
|
|
user_id: String,
|
|
device_id: Option<String>,
|
|
}
|
|
|
|
/// Get current user identity
|
|
pub async fn who_am_i(auth: APIClientAuth) -> HttpResult {
|
|
let res = auth
|
|
.send_request(account::whoami::v3::Request::default())
|
|
.await?;
|
|
|
|
Ok(HttpResponse::Ok().json(WhoAmIResponse {
|
|
user_id: res.user_id.to_string(),
|
|
device_id: res.device_id.as_deref().map(DeviceId::to_string),
|
|
}))
|
|
}
|