Fix returned error caused by unknown username in validate credentials

This commit is contained in:
indirection42 2024-03-06 15:42:51 +08:00
parent a48a2a2472
commit 2a6c7a566a

View file

@ -58,11 +58,24 @@ pub async fn validate_credentials(
expected_password_hash = stored_password_hash;
}
spawn_blocking_with_tracing(move || {
match spawn_blocking_with_tracing(move || {
verify_password_hash(expected_password_hash, credentials.password)
})
.await
.context("Failed to spawn blocking task.")??;
.context("Failed to spawn blocking task.")?
{
Ok(_) => Ok(()),
Err(e) => match e {
AuthError::InvalidCredentials(_) => {
if user_id.is_none() {
Ok(())
} else {
Err(e)
}
}
_ => Err(e),
},
}?;
user_id
.ok_or_else(|| anyhow::anyhow!("Unknown username."))