using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Identity.Web; using OnlyPrompt.Backend.Database; using OnlyPrompt.Backend.Database.Models; using OnlyPrompt.Backend.Services.Jwt; using OnlyPrompt.Backend.Utils; using Scalar.AspNetCore; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme); builder.Services.AddDbContext(opts => { opts.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")); opts.UseLazyLoadingProxies(); }); builder.Services.AddSingleton, PasswordHasher>(); builder.Services.AddSingleton(); builder.Services.AddAutoMapper(AutoMapperSetup.Setup); builder.Services.AddAuthorization(); builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, opts => { opts.Events = new JwtBearerEvents { OnMessageReceived = context => { if (context.Request.Cookies.ContainsKey("jwt")) context.Token = context.Request.Cookies["jwt"]; return Task.CompletedTask; } }; }); builder.Services.AddControllers(); builder.Services.AddOpenApi(opts => opts.AddScalarTransformers()); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.MapOpenApi(); app.MapScalarApiReference(); } app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.Run();