Add ASP.NET Identity (cookie auth) and role seeding

This commit is contained in:
2026-06-11 18:26:34 +00:00
parent 824a27520d
commit 8a7d01ac9e
9 changed files with 815 additions and 3 deletions
+10 -2
View File
@@ -1,3 +1,4 @@
using backend.Auth;
using backend.Data;
using Microsoft.EntityFrameworkCore;
@@ -6,14 +7,21 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<AppDbContext>(opt =>
opt.UseSqlite(builder.Configuration.GetConnectionString("Default")));
builder.Services.AddAppIdentity();
builder.Services.AddAuthorization();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
db.Database.Migrate();
var sp = scope.ServiceProvider;
sp.GetRequiredService<AppDbContext>().Database.Migrate();
await IdentitySetup.SeedRolesAsync(sp);
}
app.UseAuthentication();
app.UseAuthorization();
app.MapGet("/health", () => Results.Ok(new { ok = true }));
app.Run();