Skip to main content
POST
https://api.econpay.com.br
/
auth
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"
    }
  }
}

Descrição

Endpoint para autenticação de usuários. Retorna um token JWT que deve ser usado no header Authorization de todas as requisições subsequentes.
O token JWT expira em 1 hora. Após expirar, você precisará fazer login novamente.

Request Body

email
string
required
Email do usuário cadastrado
password
string
required
Senha do usuário

Response

response
object
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"
    }
  }
}

Usando o Token

Após obter o token, inclua-o no header Authorization de todas as requisições:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Renovação de Token

O token expira em 1 hora. Implemente lógica para renovar automaticamente:
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();