Can get current user identity

This commit is contained in:
2025-02-03 22:34:13 +01:00
parent 8df3afe75e
commit e6b347f90f
9 changed files with 441 additions and 23 deletions

23
src/server/api/account.rs Normal file
View File

@ -0,0 +1,23 @@
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),
}))
}

10
src/server/api/mod.rs Normal file
View File

@ -0,0 +1,10 @@
use crate::extractors::client_auth::APIClientAuth;
use crate::server::HttpResult;
use actix_web::HttpResponse;
pub mod account;
/// API Home route
pub async fn api_home(auth: APIClientAuth) -> HttpResult {
Ok(HttpResponse::Ok().body(format!("Welcome user {}!", auth.user.user_id.0)))
}