using ErsatzTV.Core.Domain; using ErsatzTV.Infrastructure.Data; using Microsoft.EntityFrameworkCore; namespace ErsatzTV.Application.Auth; public class RotateLocalAdminSecurityStampHandler(IDbContextFactory dbContextFactory) : IRequestHandler { public async Task Handle(RotateLocalAdminSecurityStamp request, CancellationToken cancellationToken) { await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); ConfigElement stampRow = await dbContext.ConfigElements .FirstOrDefaultAsync(c => c.Key == ConfigElementKey.AuthSecurityStamp.Key, cancellationToken); // No local admin configured → nothing to revoke. if (stampRow is null) { return Unit.Default; } stampRow.Value = LocalAdminHelpers.NewSecurityStamp(); await dbContext.SaveChangesAsync(cancellationToken); return Unit.Default; } }