perf: avoid cloning when checking access
This commit is contained in:
parent
7b86706793
commit
2864196584
2 changed files with 3 additions and 3 deletions
|
@ -15,10 +15,10 @@ pub fn web() -> Scope {
|
||||||
.service(refresh::res)
|
.service(refresh::res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn check_access_token(access_token: String, pool: sqlx::Pool<Postgres>) -> Result<Uuid, HttpResponse> {
|
pub async fn check_access_token<'a>(access_token: String, pool: &'a sqlx::Pool<Postgres>) -> Result<Uuid, HttpResponse> {
|
||||||
match sqlx::query_as("SELECT CAST(uuid as VARCHAR), created FROM access_tokens WHERE token = $1")
|
match sqlx::query_as("SELECT CAST(uuid as VARCHAR), created FROM access_tokens WHERE token = $1")
|
||||||
.bind(&access_token)
|
.bind(&access_token)
|
||||||
.fetch_one(&pool)
|
.fetch_one(&*pool)
|
||||||
.await {
|
.await {
|
||||||
Ok(row) => {
|
Ok(row) => {
|
||||||
let (uuid, created): (String, i64) = row;
|
let (uuid, created): (String, i64) = row;
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub async fn res(mut payload: web::Payload, path: web::Path<(String,)>, data: we
|
||||||
|
|
||||||
let authentication_request = serde_json::from_slice::<AuthenticationRequest>(&body)?;
|
let authentication_request = serde_json::from_slice::<AuthenticationRequest>(&body)?;
|
||||||
|
|
||||||
let authorized = check_access_token(authentication_request.access_token, data.pool.clone()).await;
|
let authorized = check_access_token(authentication_request.access_token, &data.pool).await;
|
||||||
|
|
||||||
if authorized.is_err() {
|
if authorized.is_err() {
|
||||||
return Ok(authorized.unwrap_err())
|
return Ok(authorized.unwrap_err())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue