Skip to main content

tuwunel_api_client/dehydrated_device/
put_dehydrated_device.rs

1use axum::extract::State;
2use ruma::api::client::dehydrated_device::put_dehydrated_device::unstable::{Request, Response};
3use tuwunel_core::Result;
4
5use crate::{ClientIp, Ruma};
6
7/// # `PUT /_matrix/client/../dehydrated_device`
8///
9/// Creates or overwrites the user's dehydrated device.
10///
11/// Any existing dehydrated device is removed first, then the new one is
12/// created with the keys the request uploads.
13#[tracing::instrument(
14	level = "debug",
15	skip_all,
16	fields(
17		%client,
18	),
19)]
20pub(crate) async fn put_dehydrated_device_route(
21	State(services): State<crate::State>,
22	ClientIp(client): ClientIp,
23	body: Ruma<Request>,
24) -> Result<Response> {
25	let sender_user = body
26		.sender_user
27		.as_deref()
28		.expect("AccessToken authentication required");
29
30	let device_id = body.body.device_id.clone();
31
32	services
33		.users
34		.set_dehydrated_device(sender_user, body.body)
35		.await?;
36
37	Ok(Response { device_id })
38}