Skip to content

Commit

Permalink
Actually delete tokens earlier not later than some date...
Browse files Browse the repository at this point in the history
  • Loading branch information
h3ndrk committed Dec 1, 2023
1 parent 8a7d017 commit 0d5756c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/application/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<
now + Duration::from_secs(60 * 60 * 24 * 7),
)
.await?;
self.token_repository.delete_later_than(now).await?;
self.token_repository.delete_earlier_than(now).await?;

Ok(Response::Success {
user_id,
Expand Down Expand Up @@ -145,7 +145,7 @@ impl<
now + Duration::from_secs(60 * 60 * 24 * 7),
)
.await?;
self.token_repository.delete_later_than(now).await?;
self.token_repository.delete_earlier_than(now).await?;

Ok(Response::Success {
user_id,
Expand All @@ -156,7 +156,7 @@ impl<

async fn relogin(&self, token: &str) -> Result<Response, Error> {
self.token_repository
.delete_later_than(SystemTime::now())
.delete_earlier_than(SystemTime::now())
.await?;

let Some(user_id) = self.token_repository.get_user_id(token).await? else {
Expand Down
6 changes: 3 additions & 3 deletions src/persistence/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub trait TokenRepository {
user_id: i64,
expires_at: SystemTime,
) -> Result<(), Error>;
async fn delete_later_than(&self, deadline: SystemTime) -> Result<(), Error>;
async fn delete_earlier_than(&self, deadline: SystemTime) -> Result<(), Error>;
async fn get_user_id(&self, token: &str) -> Result<Option<i64>, Error>;
async fn get_all(&self) -> Result<Vec<Token>, Error>;
async fn clear(&self) -> Result<(), Error>;
Expand Down Expand Up @@ -54,8 +54,8 @@ impl TokenRepository for SqliteTokenRepository {
.map(|_| ())
}

async fn delete_later_than(&self, deadline: SystemTime) -> Result<(), Error> {
query("DELETE FROM tokens WHERE expires_at > ?")
async fn delete_earlier_than(&self, deadline: SystemTime) -> Result<(), Error> {
query("DELETE FROM tokens WHERE expires_at < ?")
.bind(deadline.duration_since(UNIX_EPOCH).unwrap().as_secs() as i64)
.execute(self.pool.as_ref())
.await
Expand Down

0 comments on commit 0d5756c

Please sign in to comment.