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",
|
"target": "ESNext",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"moduleResolution": "Node",
|
"moduleResolution": "Node",
|
||||||
|
"ignoreDeprecations": "6.0",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
|
|||||||
@@ -53,8 +53,12 @@ pub async fn org_extractor_middleware(
|
|||||||
.map_err(|_| StatusCode::UNAUTHORIZED)?
|
.map_err(|_| StatusCode::UNAUTHORIZED)?
|
||||||
.claims;
|
.claims;
|
||||||
|
|
||||||
// Forzar el uso de la organización por defecto para arquitectura single-tenant
|
let org_id = req
|
||||||
let org_id = Uuid::parse_str("00000000-0000-0000-0000-000000000001").unwrap();
|
.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.
|
// Insertamos el contexto y las claims en las extensiones de la petición.
|
||||||
req.extensions_mut().insert(OrgContext { id: org_id });
|
req.extensions_mut().insert(OrgContext { id: org_id });
|
||||||
@@ -92,6 +96,10 @@ where
|
|||||||
if let Some(org_context) = parts.extensions.get::<OrgContext>() {
|
if let Some(org_context) = parts.extensions.get::<OrgContext>() {
|
||||||
return Ok(Org(org_context.clone()));
|
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)
|
// Fallback: usar org por defecto (single-tenant architecture)
|
||||||
// Este fallback es necesario si el middleware no ejecutó correctamente
|
// Este fallback es necesario si el middleware no ejecutó correctamente
|
||||||
|
|||||||
Reference in New Issue
Block a user