diff --git a/backend/newwhats/proxy.js b/backend/newwhats/proxy.js index c5ffa24..5a4f405 100644 --- a/backend/newwhats/proxy.js +++ b/backend/newwhats/proxy.js @@ -35,6 +35,8 @@ export function createRestProxy() { 'Content-Type': 'application/json', 'x-nw-key': cfg.integrationKey, 'x-nw-email': email, + // clínica do workspace ativo (modelo de canal) — repassa ao motor se veio. + ...(req.headers['x-nw-clinica'] ? { 'x-nw-clinica': String(req.headers['x-nw-clinica']) } : {}), } }; if (!['GET', 'HEAD'].includes(req.method) && req.body && Object.keys(req.body).length) { opts.body = JSON.stringify(req.body); diff --git a/frontend/views/newwhats/services/nwClient.ts b/frontend/views/newwhats/services/nwClient.ts index c05ee40..35e1e79 100644 --- a/frontend/views/newwhats/services/nwClient.ts +++ b/frontend/views/newwhats/services/nwClient.ts @@ -9,9 +9,19 @@ export function nwToken(): string | null { try { return localStorage.getItem(TOKEN_KEY); } catch { return null; } } +// Clínica do workspace ativo — escopo por-requisição (modelo de canal). +function activeClinicaId(): string | null { + try { return JSON.parse(localStorage.getItem('SCOREODONTO_ACTIVE_WORKSPACE') || '{}')?.id || null; } catch { return null; } +} + function authHeaders(extra?: Record): Record { const t = nwToken(); - return { ...(t ? { Authorization: `Bearer ${t}` } : {}), ...(extra || {}) }; + const c = activeClinicaId(); + return { + ...(t ? { Authorization: `Bearer ${t}` } : {}), + ...(c ? { 'x-nw-clinica': c } : {}), + ...(extra || {}), + }; } async function req(method: string, path: string, body?: any): Promise {