Added a "refreshed_at" stat to tokens.

This commit is contained in:
Rogier Reerink
2026-10-08 16:04:53 +02:00
parent 8576da980e
commit a2ca1c60e5
8 changed files with 16 additions and 8 deletions
+1
View File
@@ -7,6 +7,7 @@ pub struct TokenRow {
pub refresh_token_hash: Vec<u8>,
pub access_expires_at: DateTime<Utc>,
pub refresh_expires_at: DateTime<Utc>,
pub refreshed_at: Option<DateTime<Utc>>,
pub revoked_at: Option<DateTime<Utc>>,
pub created_at: DateTime<Utc>,
}
+5 -3
View File
@@ -10,15 +10,16 @@ where
r#"
INSERT INTO tokens (
id, access_token_hash, refresh_token_hash,
access_expires_at, refresh_expires_at, revoked_at, created_at
access_expires_at, refresh_expires_at, refreshed_at, revoked_at, created_at
)
VALUES ($1, $2, $3, $4, $5, $6, $7)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
"#,
token.id,
token.access_token_hash,
token.refresh_token_hash,
token.access_expires_at,
token.refresh_expires_at,
token.refreshed_at,
token.revoked_at,
token.created_at,
)
@@ -46,7 +47,8 @@ where
SET access_token_hash = $2,
refresh_token_hash = $3,
access_expires_at = $4,
refresh_expires_at = $5
refresh_expires_at = $5,
refreshed_at = now()
WHERE refresh_token_hash = $1
AND revoked_at IS NULL
AND refresh_expires_at > now()
+1
View File
@@ -8,6 +8,7 @@ pub struct Token {
pub refresh_token_hash: Vec<u8>,
pub access_expires_at: DateTime<Utc>,
pub refresh_expires_at: DateTime<Utc>,
pub refreshed_at: Option<DateTime<Utc>>,
pub revoked_at: Option<DateTime<Utc>>,
pub created_at: DateTime<Utc>,
}
+1
View File
@@ -49,6 +49,7 @@ fn encode(token: Token) -> TokenRow {
refresh_token_hash: token.refresh_token_hash,
access_expires_at: token.access_expires_at,
refresh_expires_at: token.refresh_expires_at,
refreshed_at: token.refreshed_at,
revoked_at: token.revoked_at,
created_at: token.created_at,
}
+1
View File
@@ -117,6 +117,7 @@ fn token(generated: &GeneratedTokenPair) -> Token {
refresh_token_hash: generated.refresh_token_hash.clone(),
access_expires_at: generated.access_expires_at,
refresh_expires_at: generated.refresh_expires_at,
refreshed_at: None,
revoked_at: None,
created_at: Utc::now(),
}