fix(backend): update middleware ordering and interceptors for RLS
Update TenantValidationMiddleware, Program.cs startup sequence, SaveChangesTenantInterceptor, and TenantProvider to ensure proper middleware ordering and tenant context initialization before database access. Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Finbuckle.MultiTenant;
|
||||
using Finbuckle.MultiTenant.Abstractions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -9,14 +8,14 @@ namespace WorkClub.Infrastructure.Data.Interceptors;
|
||||
|
||||
public class SaveChangesTenantInterceptor : SaveChangesInterceptor
|
||||
{
|
||||
private readonly IMultiTenantContextAccessor _tenantAccessor;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly ILogger<SaveChangesTenantInterceptor> _logger;
|
||||
|
||||
public SaveChangesTenantInterceptor(
|
||||
IMultiTenantContextAccessor tenantAccessor,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
ILogger<SaveChangesTenantInterceptor> logger)
|
||||
{
|
||||
_tenantAccessor = tenantAccessor;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -42,7 +41,7 @@ public class SaveChangesTenantInterceptor : SaveChangesInterceptor
|
||||
if (context == null)
|
||||
return;
|
||||
|
||||
var tenantId = _tenantAccessor.MultiTenantContext?.TenantInfo?.Identifier;
|
||||
var tenantId = _httpContextAccessor.HttpContext?.Items["TenantId"] as string;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(tenantId))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user