From 5877de6c3bd5de0f20a16aa896e8ad5d7e1cc0f9 Mon Sep 17 00:00:00 2001 From: Alessandro Bono Date: Wed, 1 May 2024 20:00:49 +0200 Subject: [PATCH] gdm/util: Simplify code This avoids iterating and checking if a service is foreground multiple times. Part-of: --- js/gdm/util.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/js/gdm/util.js b/js/gdm/util.js index 303be0d62..b5a544c8d 100644 --- a/js/gdm/util.js +++ b/js/gdm/util.js @@ -892,10 +892,10 @@ export class ShellUserVerifier extends Signals.EventEmitter { // If the login failed with the preauthenticated oVirt credentials // then discard the credentials and revert to default authentication // mechanism. - let foregroundService = Object.keys(this._credentialManagers).find(service => - this.serviceIsForeground(service)); - if (foregroundService) { - this._credentialManagers[foregroundService].token = null; + const isCredentialManager = !!this._credentialManagers[serviceName]; + const isForeground = this.serviceIsForeground(serviceName); + if (isCredentialManager && isForeground) { + this._credentialManagers[serviceName].token = null; this._preemptingService = null; this._verificationFailed(serviceName, false); return; @@ -909,7 +909,7 @@ export class ShellUserVerifier extends Signals.EventEmitter { // if the password service fails, then cancel everything. // But if, e.g., fingerprint fails, still give // password authentication a chance to succeed - if (this.serviceIsForeground(serviceName)) + if (isForeground) this._failCounter++; this._verificationFailed(serviceName, true);