Added authenication/authorization. Refactored api startup.
This commit is contained in:
30
JSMR.Api/Startup/DevSeeding.cs
Normal file
30
JSMR.Api/Startup/DevSeeding.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using JSMR.Domain.Entities;
|
||||
using JSMR.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace JSMR.Api.Startup;
|
||||
|
||||
public static class DevSeeding
|
||||
{
|
||||
public static async Task SeedDevelopmentAsync(this WebApplication app)
|
||||
{
|
||||
using var scope = app.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
|
||||
var username = "brister";
|
||||
|
||||
if (!await db.Users.AnyAsync(u => u.Username == username))
|
||||
{
|
||||
db.Users.Add(new User
|
||||
{
|
||||
Username = username,
|
||||
PasswordHash = BCrypt.Net.BCrypt.HashPassword("password"),
|
||||
Role = "Admin",
|
||||
IsActive = true
|
||||
});
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
Console.WriteLine("✅ Seeded development user: brister / password");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user