Skip to main content

tuwunel_api/client/account/
whoami.rs

1use axum::extract::State;
2use ruma::api::client::account::whoami;
3use tuwunel_core::{Result, err};
4
5use crate::Ruma;
6
7/// # `GET _matrix/client/r0/account/whoami`
8///
9/// Get `user_id` of the sender user.
10///
11/// Note: Also works for Application Services
12pub(crate) async fn whoami_route(
13	State(services): State<crate::State>,
14	body: Ruma<whoami::v3::Request>,
15) -> Result<whoami::v3::Response> {
16	Ok(whoami::v3::Response {
17		user_id: body.sender_user().to_owned(),
18		device_id: body.sender_device.clone(),
19		is_guest: body.appservice_info.is_none()
20			&& services
21				.users
22				.is_deactivated(body.sender_user())
23				.await
24				.map_err(|_| err!(Request(Forbidden("User does not exist."))))?,
25	})
26}