summaryrefslogtreecommitdiff
path: root/src/repo/token.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-01 20:32:57 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-01 20:32:57 -0400
commit7645411bcf7201e3a4927566da78080dc6a84ccf (patch)
tree2711922bfeab6dc8b6494e9b0976f3f051dff4a9 /src/repo/token.rs
parent6c054c5b8d43a818ccfa9087960dc19b286e6bb7 (diff)
Prevent racing between `limit_stream` and logging out.
Diffstat (limited to 'src/repo/token.rs')
-rw-r--r--src/repo/token.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/repo/token.rs b/src/repo/token.rs
index d96c094..1663f5e 100644
--- a/src/repo/token.rs
+++ b/src/repo/token.rs
@@ -47,6 +47,21 @@ impl<'c> Tokens<'c> {
Ok(secret)
}
+ pub async fn require(&mut self, token: &Id) -> Result<(), sqlx::Error> {
+ sqlx::query_scalar!(
+ r#"
+ select id as "id: Id"
+ from token
+ where id = $1
+ "#,
+ token,
+ )
+ .fetch_one(&mut *self.0)
+ .await?;
+
+ Ok(())
+ }
+
// Revoke a token by its secret.
pub async fn revoke(&mut self, token: &Id) -> Result<(), sqlx::Error> {
sqlx::query_scalar!(