♻️ Better updating device name

This commit is contained in:
2025-06-07 22:55:47 +08:00
parent 3a978441b6
commit 9d534660af
2 changed files with 21 additions and 11 deletions

View File

@ -328,11 +328,17 @@ public class AccountService(
.Where(s => s.Id == sessionId && s.AccountId == account.Id)
.FirstOrDefaultAsync();
if (session is null) throw new InvalidOperationException("Session was not found.");
session.Label = label;
await db.SaveChangesAsync();
await cache.RemoveAsync($"{DysonTokenAuthHandler.AuthCachePrefix}{session.Id}");
await db.AuthChallenges
.Where(s => s.DeviceId == session.Challenge.DeviceId)
.ExecuteUpdateAsync(p => p.SetProperty(s => s.DeviceId, label));
var sessions = await db.AuthSessions
.Include(s => s.Challenge)
.Where(s => s.AccountId == session.Id && s.Challenge.DeviceId == session.Challenge.DeviceId)
.ToListAsync();
foreach(var item in sessions)
await cache.RemoveAsync($"{DysonTokenAuthHandler.AuthCachePrefix}{item.Id}");
return session;
}