From 555aea225285db4802f9a6ca9d5d33f8c95dbf24 Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Wed, 4 Sep 2024 12:15:45 -0400 Subject: [PATCH] Refactor credential counter update Simplify the update of credential counters by replacing a map statement with an if let statement. Additionally, add a FIXME comment to integrate blockchain recording and replay attack checks in the future. --- src/authn.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/authn.rs b/src/authn.rs index ded4d08..f7a7430 100644 --- a/src/authn.rs +++ b/src/authn.rs @@ -332,16 +332,13 @@ pub async fn finish_authentication( { Ok(auth_result) => { let mut users_guard = app_state.accounts.lock().await; - // Update the credential counter, if possible. - users_guard - .keys - .get_mut(&user_unique_id) - .map(|keys| { - keys.iter_mut().for_each(|sk| { - sk.update_credential(&auth_result); - }) - }) - .ok_or(UserHasNoCredentials)?; + // Update the credential counter, if possible. + // FIXME record on blockchain, then check above for replay attach + if let Some(keys) = users_guard.keys.get_mut(&user_unique_id) { + keys.iter_mut().for_each(|sk| { + sk.update_credential(&auth_result); + }); + } // Generate JWT token let token = generate_jwt(user_unique_id, &app_state)?; // Return JSON response with JWT token