UserAuthenticator: propagate token creation errors

This commit is contained in:
Xiretza 2024-02-10 12:39:07 +00:00
parent 51865c365c
commit 3657d83bd1

View file

@ -43,16 +43,20 @@ impl UserAuthenticator {
}
#[instrument]
pub async fn create_user_token(&mut self, username: &str, password: &Password) -> UserToken {
pub async fn create_user_token(
&mut self,
username: &str,
password: &Password,
) -> Result<UserToken, AuthenticationError> {
// TODO: validate password
let new_token =
UserToken::from(Alphanumeric.sample_string(&mut thread_rng(), Self::TOKEN_LEN));
let mut db = self.db.lock().await;
if let Err(err) = db.save_token(username, &new_token).await {
event!(Level::ERROR, %err, "Failed to save token in database");
}
db.save_token(username, &new_token).await?;
new_token
Ok(new_token)
}
#[instrument]