ezidam: refactor jwt and refresh token generate in "tokens" mod

This commit is contained in:
Philippe Loctaux 2023-03-26 19:25:50 +02:00
parent 23b1e3ea4f
commit 9687116063
13 changed files with 179 additions and 59 deletions

View file

@ -63,4 +63,17 @@ impl Keys {
}
}
}
pub async fn revoke_all_except_one(
conn: impl SqliteExecutor<'_>,
exception: &str,
) -> Result<Option<()>, Error> {
let query: SqliteQueryResult =
sqlx::query_file!("queries/keys/revoke_all_except_one.sql", exception)
.execute(conn)
.await
.map_err(handle_error)?;
Ok((query.rows_affected() >= 1).then_some(()))
}
}

View file

@ -59,6 +59,15 @@ impl RefreshTokens {
Ok((query.rows_affected() == 1).then_some(()))
}
pub async fn revoke_all(conn: impl SqliteExecutor<'_>) -> Result<Option<()>, Error> {
let query: SqliteQueryResult = sqlx::query_file!("queries/refresh_tokens/revoke_all.sql")
.execute(conn)
.await
.map_err(handle_error)?;
Ok((query.rows_affected() >= 1).then_some(()))
}
pub async fn revoke_all_for_user(
conn: impl SqliteExecutor<'_>,
user: &str,