WorkTracker/Services/Auth/SingleUserSeedService.cs
MaddoScientisto 7029e374cc
Some checks failed
Publish Container / publish (push) Has been cancelled
Refactor authentication system to use MongoDB
- Removed Entity Framework Core identity schema and related migrations.
- Introduced MongoDB-based authentication service with user seeding functionality.
- Updated Program.cs to configure authentication and authorization using cookies.
- Created new Login.razor component for user login interface.
- Added RedirectToLogin component for handling unauthorized access.
- Updated Dockerfile and docker-compose files for development and production environments.
- Removed SQLite connection strings and related configurations.
- Added MongoDB connection settings in appsettings.json and Docker configurations.
- Implemented IMongoAuthService interface and MongoAuthService class for user management.
- Created MongoAuthUser model for MongoDB user representation.
2026-03-16 21:54:44 +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 IMongoAuthService authService;
private readonly IOptions<SingleUserOptions> options;
private readonly ILogger<SingleUserSeedService> logger;
public SingleUserSeedService(
IMongoAuthService 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 MongoDB single user account {Email}", options.Value.Email);
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}