fix: Overwrite previous access token on non-retry refreshes

Previously, set_token skipped saving the replaced access token whenever
a previous token entry already existed. If a client refreshed again with
its current refresh token before making a valid API request (such as
after going idle until expiry), a dropped response would leave the
server holding an older access token and cause a hard logout.

Let callers explicitly specify whether to clear, replace, or preserve
the previous access token.
This commit is contained in:
Jade Ellis committed 2026-11-27 18:41:45 +00:00
1 parent 25464134d8
commit 6412a650a5
4 files changed
+44 -12

No files matched your search

+2 -2
View File
@@ -28,7 +28,7 @@ use ruma::{
},
assign,
};
use service::users::DeviceToken;
use service::users::{DeviceToken, PreviousTokenAction};
use crate::{Ruma, client_ip::ClientIp};
@@ -205,7 +205,7 @@ pub(crate) async fn login_route(
let device_id = if let Some(existing_device_id) = existing_device_id {
services
.users
.set_token(&user_id, &existing_device_id, token.clone())
.set_token(&user_id, &existing_device_id, token.clone(), PreviousTokenAction::Clear)
.await?;
existing_device_id