Refactor runtime bootstrap and ship control flows
This commit is contained in:
33
apps/backend/Auth/Simulation/DevAuthSeeder.cs
Normal file
33
apps/backend/Auth/Simulation/DevAuthSeeder.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace SpaceGame.Api.Auth.Simulation;
|
||||
|
||||
public sealed class DevAuthSeeder(
|
||||
IHostEnvironment hostEnvironment,
|
||||
IOptions<AuthOptions> authOptions,
|
||||
IAuthRepository authRepository,
|
||||
LocalPasswordHasher passwordHasher)
|
||||
{
|
||||
public async Task SeedAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (!hostEnvironment.IsDevelopment())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var seedUser in authOptions.Value.DevSeedUsers)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(seedUser.Email) || string.IsNullOrWhiteSpace(seedUser.Password))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
await authRepository.UpsertUserAsync(
|
||||
seedUser.Email.Trim().ToLowerInvariant(),
|
||||
passwordHasher.HashPassword(seedUser.Password),
|
||||
seedUser.Roles,
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user