Skip to main content

Verificação de Auth dos Clientes — #08 Cross-Tenant

Data: 2026-07-08 Objetivo: Confirmar que zzapp e zzportal já enviam Authorization: Bearer em todas as requests para /api/payment/*.


1. zzapp (Flutter)

1.1 Mecanismo de auth

Arquivo: coezzion_vendas_app/lib/middlewares/http/auth_interceptor.dart

// Linha 20 — adicionado em TODAS as requests
final auth = await Get.find<AuthController>(tag: "auth").auth;

if (auth != null) {
options.headers['Authorization'] = 'Bearer ${auth.accessToken}';
}

Arquivo: coezzion_vendas_app/lib/shared/utils/dio_utils.dart

// Linhas 84-95 — interceptors registrados no Dio global
dio.interceptors.addAll([
AuthInterceptor(), // ← Bearer token
RefreshTokenInterceptor(), // ← retry em 401
SchemaInterceptor(), // ← api-company-target (só em /api/payment)
BrandsInterceptor(), // ← X-Request-brands
DeviceIdInterceptor(), // ← X-device-id
]);

O AuthInterceptor é incondicional — adiciona Bearer a toda request, sem filtrar por path.

1.2 Endpoints chamados

EndpointAtivo?Envia Bearer?
GET /api/payment/profile-fraudNão (código comentado)Sim (se ativo)
GET /api/payment-report/report/sales/{orderId}/5SimSim
GET /api/payment-report/dashboard/appSimSim
GET /api/store/payment/{storeId}/appSimSim

1.3 Schema interceptor

Arquivo: coezzion_vendas_app/lib/middlewares/http/schema_interceptor.dart

// Linha 21-26 — só adiciona api-company-target se URL contém /api/payment
if (path.contains(ApiUtils.linkApi)) {
options.headers['api-company-target'] = schema;
}

Adiciona o header api-company-target junto com o Bearer, não no lugar dele.


2. zzportal (React)

2.1 Mecanismo de auth

Arquivo: coezzion-portal/src/store/auth/index.ts

// Linhas 17-19 — sign-in
api.defaults.headers.Authorization = `Bearer ${token}`;
api.defaults.headers['api-company-target'] = schema;

// Linhas 33-35 — refresh token
api.defaults.headers.Authorization = `Bearer ${token}`;
api.defaults.headers['api-company-target'] = schema;

Arquivo: coezzion-portal/src/store/index.ts

// Linhas 48-53 — rehydration (page reload)
persistStore(store, null, () => {
const state = store.getState();
if (state.auth.token) {
api.defaults.headers.Authorization = `Bearer ${state.auth.token}`;
api.defaults.headers['api-company-target'] = state.user.organizationToken.schema ?? '';
}
});

api.defaults.headers.commontodas as requests do axios recebem Bearer automaticamente.

2.2 Endpoints chamados

EndpointMétodoEnvia Bearer?
/api/payment/profile-fraudGET, POST, DELETESim
/api/payment/approvePOSTSim
/api/payment/reversePOSTSim
/api/payment/cancelPOSTSim
/api/payment/antifraud/retry/{id}POSTSim
/api/payment/history/{id}GETSim
/api/payment/control-operation/storePUT, POST, DELETESim
/api/payment/control-operationPUTSim

2.3 Token refresh

Arquivo: coezzion-portal/src/services/api.ts (linhas 18-68)

Response interceptor no axios:

  1. Detecta 401 → chama POST api/auth/refresh-token
  2. Atualiza Authorization header com novo token
  3. Retry da request original

3. Conclusão

ClienteBearer em todas requests?Mecanismo
zzapp✅ SimAuthInterceptor incondicional
zzportal✅ Simapi.defaults.headers.common global

Adicionar [Authorize(JwtBearer)] aos endpoints /api/payment/* não causa breaking change em nenhum dos dois clientes.