feat: mejorar la extracción del contexto de organización en el middleware

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-25 11:30:38 -04:00
parent f304ed1b50
commit 675fa1e299
2 changed files with 11 additions and 2 deletions
+1
View File
@@ -3,6 +3,7 @@
"target": "ESNext",
"module": "commonjs",
"moduleResolution": "Node",
"ignoreDeprecations": "6.0",
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true,
+10 -2
View File
@@ -53,8 +53,12 @@ pub async fn org_extractor_middleware(
.map_err(|_| StatusCode::UNAUTHORIZED)?
.claims;
// Forzar el uso de la organización por defecto para arquitectura single-tenant
let org_id = Uuid::parse_str("00000000-0000-0000-0000-000000000001").unwrap();
let org_id = req
.headers()
.get("x-organization-id")
.and_then(|value| value.to_str().ok())
.and_then(|value| Uuid::parse_str(value).ok())
.unwrap_or(claims.org);
// Insertamos el contexto y las claims en las extensiones de la petición.
req.extensions_mut().insert(OrgContext { id: org_id });
@@ -92,6 +96,10 @@ where
if let Some(org_context) = parts.extensions.get::<OrgContext>() {
return Ok(Org(org_context.clone()));
}
if let Some(claims) = parts.extensions.get::<Claims>() {
return Ok(Org(OrgContext { id: claims.org }));
}
// Fallback: usar org por defecto (single-tenant architecture)
// Este fallback es necesario si el middleware no ejecutó correctamente