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:
@@ -3,6 +3,7 @@
|
||||
"target": "ESNext",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "Node",
|
||||
"ignoreDeprecations": "6.0",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"esModuleInterop": true,
|
||||
|
||||
@@ -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 });
|
||||
@@ -93,6 +97,10 @@ where
|
||||
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
|
||||
let default_org_id = Uuid::parse_str("00000000-0000-0000-0000-000000000001")
|
||||
|
||||
Reference in New Issue
Block a user