WorkTracker/Services/Auth/SingleUserSeedService.cs
2026-03-17 13:53:33 +01:00

40 lines
1.1 KiB
C#

using Microsoft.Extensions.Options;
using WorkTracker.Configuration;
namespace WorkTracker.Services.Auth;
public sealed class SingleUserSeedService : IHostedService
{
private readonly IAuthService authService;
private readonly IOptions<SingleUserOptions> options;
private readonly ILogger<SingleUserSeedService> logger;
public SingleUserSeedService(
IAuthService authService,
IOptions<SingleUserOptions> options,
ILogger<SingleUserSeedService> logger)
{
this.authService = authService;
this.options = options;
this.logger = logger;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
if (!options.Value.SeedOnStartup)
{
return;
}
try
{
await authService.EnsureSeedUserAsync(cancellationToken);
}
catch (Exception ex)
{
logger.LogError(ex, "Unable to seed Couchbase Lite single user account {Email}", options.Value.Email);
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}