🐛 Yeah, another bug fix

This commit is contained in:
LittleSheep 2025-06-06 01:00:22 +08:00
parent aef6c60621
commit bb7c9ca9d8

View File

@ -169,7 +169,7 @@ public class AccountService(
if (factor.EnabledAt is null) throw new ArgumentException("The factor has been disabled."); if (factor.EnabledAt is null) throw new ArgumentException("The factor has been disabled.");
var count = await db.AccountAuthFactors var count = await db.AccountAuthFactors
.Where(f => f.AccountId == factor.Id && f.EnabledAt != null) .Where(f => f.AccountId == factor.AccountId && f.EnabledAt != null)
.CountAsync(); .CountAsync();
if (count <= 1) if (count <= 1)
throw new InvalidOperationException( throw new InvalidOperationException(
@ -182,7 +182,8 @@ public class AccountService(
public async Task DeleteAuthFactor(AccountAuthFactor factor) public async Task DeleteAuthFactor(AccountAuthFactor factor)
{ {
var count = await db.AccountAuthFactors var count = await db.AccountAuthFactors
.Where(f => f.AccountId == factor.Id) .Where(f => f.AccountId == factor.AccountId)
.If(factor.EnabledAt is not null, q => q.Where(f => f.EnabledAt != null))
.CountAsync(); .CountAsync();
if (count <= 1) if (count <= 1)
throw new InvalidOperationException("Deleting this auth factor will cause you have no auth factor."); throw new InvalidOperationException("Deleting this auth factor will cause you have no auth factor.");