Skip to content

Commit 0f3b2d2

Browse files
reivilibresandhose
authored andcommitted
When consuming a compat refresh token, consume others in the session
1 parent 5ce953b commit 0f3b2d2

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/src/compat/refresh_token.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,25 @@ impl CompatRefreshTokenRepository for PgCompatRefreshTokenRepository<'_> {
204204
r#"
205205
UPDATE compat_refresh_tokens
206206
SET consumed_at = $2
207-
WHERE compat_refresh_token_id = $1
207+
WHERE compat_session_id = $1
208+
AND consumed_at IS NULL
208209
"#,
209-
Uuid::from(compat_refresh_token.id),
210+
Uuid::from(compat_refresh_token.session_id),
210211
consumed_at,
211212
)
212213
.traced()
213214
.execute(&mut *self.conn)
214215
.await?;
215216

216-
DatabaseError::ensure_affected_rows(&res, 1)?;
217+
// This can affect multiple rows in case we've imported refresh tokens
218+
// from Synapse. What we care about is that it at least affected one,
219+
// which is what we're checking here
220+
if res.rows_affected() == 0 {
221+
return Err(DatabaseError::RowsAffected {
222+
expected: 1,
223+
actual: 0,
224+
});
225+
}
217226

218227
let compat_refresh_token = compat_refresh_token
219228
.consume(consumed_at)

crates/storage/src/compat/refresh_token.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ pub trait CompatRefreshTokenRepository: Send + Sync {
6969
token: String,
7070
) -> Result<CompatRefreshToken, Self::Error>;
7171

72-
/// Consume a compat refresh token
72+
/// Consume a compat refresh token.
73+
///
74+
/// This also marks other refresh tokens in the same session as consumed.
75+
/// This is desirable because the syn2mas migration process can import
76+
/// multiple refresh tokens for one device (compat session).
77+
/// But once the user uses one of those, the others should no longer
78+
/// be valid.
7379
///
7480
/// Returns the consumed compat refresh token
7581
///

0 commit comments

Comments
 (0)