Refactor TwoFactorIsEnabledQuery to streamline user ID retrieval

* Consolidated user ID retrieval logic to avoid redundancy.
* Ensured consistent handling of user ID checks for premium access queries.
* Improved code readability by reducing duplicate code blocks.
This commit is contained in:
Rui Tome 2025-12-09 14:27:54 +00:00
parent 61775fb195
commit 19627f4b56
No known key found for this signature in database
GPG Key ID: 526239D96A8EC066

View File

@ -91,14 +91,14 @@ public class TwoFactorIsEnabledQuery : ITwoFactorIsEnabledQuery
public async Task<bool> TwoFactorIsEnabledAsync(ITwoFactorProvidersUser user)
{
var userId = user.GetUserId();
if (!userId.HasValue)
{
return false;
}
if (_featureService.IsEnabled(FeatureFlagKeys.PremiumAccessQuery))
{
var userId = user.GetUserId();
if (!userId.HasValue)
{
return false;
}
var userEntity = user as User ?? await _userRepository.GetByIdAsync(userId.Value);
if (userEntity == null)
{
@ -108,17 +108,11 @@ public class TwoFactorIsEnabledQuery : ITwoFactorIsEnabledQuery
return await TwoFactorIsEnabledVNextAsync(userEntity);
}
var id = user.GetUserId();
if (!id.HasValue)
{
return false;
}
return await TwoFactorEnabledAsync(
user.GetTwoFactorProviders(),
async () =>
{
var calcUser = await _userRepository.GetCalculatedPremiumAsync(id.Value);
var calcUser = await _userRepository.GetCalculatedPremiumAsync(userId.Value);
return calcUser?.HasPremiumAccess ?? false;
});
}