curl --request POST \ --url https://api.econpay.com.br/auth \ --header 'Content-Type: application/json' \ --data '{ "email": "[email protected]", "password": "sua-senha" }'
{ "response": { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNjQwMTIzNDU2LCJleHAiOjE2NDAxMjcwNTZ9.abc123def456...", "user": { "id": 1, "name": "João da Silva", "email": "[email protected]", "role": "admin" } } }
Autenticar e obter token JWT
Authorization
Show properties
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
let token = null; let tokenExpiry = null; async function getValidToken() { // Se não tem token ou expirou, fazer login if (!token || Date.now() > tokenExpiry) { const response = await fetch('https://api.econpay.com.br/auth', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: process.env.EMAIL, password: process.env.PASSWORD }) }); const data = await response.json(); token = data.response.token; tokenExpiry = Date.now() + (3600 * 1000); // 1 hora } return token; } // Usar em requisições const validToken = await getValidToken();