Add ASP.NET Identity (cookie auth) and role seeding
This commit is contained in:
+10
-2
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user