WorkTracker/Services/Auth/SingleUserSeedService.cs

40 lines
1.1 KiB
C#
Raw Normal View History

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