:drunk: Write shit code trying to split up the Auth (WIP)

This commit is contained in:
2025-07-06 12:58:18 +08:00
parent 5757526ea5
commit 6a3d04af3d
224 changed files with 1889 additions and 36885 deletions

View File

@ -21,21 +21,30 @@ public class PermissionMiddleware(RequestDelegate next)
if (attr != null)
{
if (httpContext.Items["CurrentUser"] is not Account.Account currentUser)
if (httpContext.User.Identity?.IsAuthenticated != true)
{
httpContext.Response.StatusCode = StatusCodes.Status403Forbidden;
await httpContext.Response.WriteAsync("Unauthorized");
return;
}
if (currentUser.IsSuperuser)
var currentUserId = httpContext.User.GetUserId();
if (currentUserId == Guid.Empty)
{
// Bypass the permission check for performance
await next(httpContext);
httpContext.Response.StatusCode = StatusCodes.Status403Forbidden;
await httpContext.Response.WriteAsync("Unauthorized");
return;
}
var actor = $"user:{currentUser.Id}";
// TODO: Check for superuser from PassClient
// if (currentUser.IsSuperuser)
// {
// // Bypass the permission check for performance
// await next(httpContext);
// return;
// }
var actor = $"user:{currentUserId}";
var permNode = await pm.GetPermissionAsync<bool>(actor, attr.Area, attr.Key);
if (!permNode)