feat(Core): expose needed cookie parts to controllers

This commit is contained in:
2026-06-15 09:10:23 +02:00
parent f5701d2cdd
commit 2f1afe7cc7
2 changed files with 11 additions and 2 deletions
+7 -1
View File
@@ -1,8 +1,10 @@
using Core.Models;
namespace Core.Middlewares; namespace Core.Middlewares;
public class AuthorizationMiddleware(RequestDelegate next) public class AuthorizationMiddleware(RequestDelegate next)
{ {
public Task Invoke(HttpContext httpContext) public Task Invoke(HttpContext httpContext, CookiePlayerData playerData)
{ {
var cookieHeader = httpContext.Request.Headers.Cookie.ToString(); var cookieHeader = httpContext.Request.Headers.Cookie.ToString();
@@ -22,6 +24,10 @@ public class AuthorizationMiddleware(RequestDelegate next)
return Task.CompletedTask; return Task.CompletedTask;
} }
playerData.Uuid = httpContext.Request.Cookies["sid"]!.Split(":")[2];
playerData.Name = httpContext.Request.Cookies["user"]!;
playerData.Version = httpContext.Request.Cookies["version"]!;
return next(httpContext); return next(httpContext);
} }
} }
+4 -1
View File
@@ -1,10 +1,13 @@
using Core.Data; using Core.Data;
using Core.Helpers;
using Core.Middlewares; using Core.Middlewares;
using Core.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using AppConfig = Core.Helpers.AppConfig;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<CookiePlayerData>();
builder.Services.AddControllers(); builder.Services.AddControllers();
var connectionString = builder.Configuration.GetValue<string>("Database"); var connectionString = builder.Configuration.GetValue<string>("Database");