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,7 +1,5 @@
|
||||
using System.Security.Claims;
|
||||
using System.Text.Json;
|
||||
using Finbuckle.MultiTenant;
|
||||
using Finbuckle.MultiTenant.Abstractions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using WorkClub.Application.Interfaces;
|
||||
|
||||
@@ -9,26 +7,22 @@ namespace WorkClub.Infrastructure.Services;
|
||||
|
||||
public class TenantProvider : ITenantProvider
|
||||
{
|
||||
private readonly IMultiTenantContextAccessor _multiTenantContextAccessor;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public TenantProvider(
|
||||
IMultiTenantContextAccessor multiTenantContextAccessor,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
public TenantProvider(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_multiTenantContextAccessor = multiTenantContextAccessor;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
public string GetTenantId()
|
||||
{
|
||||
var tenantInfo = _multiTenantContextAccessor.MultiTenantContext?.TenantInfo;
|
||||
if (tenantInfo == null || string.IsNullOrEmpty(tenantInfo.Identifier))
|
||||
var tenantId = _httpContextAccessor.HttpContext?.Items["TenantId"] as string;
|
||||
if (string.IsNullOrEmpty(tenantId))
|
||||
{
|
||||
throw new InvalidOperationException("Tenant context is not available");
|
||||
}
|
||||
|
||||
return tenantInfo.Identifier;
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public string GetUserRole()
|
||||
|
||||
Reference in New Issue
Block a user