EvolutionAPI / evolution-api

Evolution API is an open-source WhatsApp integration API
https://evolution-api.com
Other
1.86k stars 985 forks source link

Error creating instance v2.1.1 #1020

Open thiago-coucello opened 19 hours ago

thiago-coucello commented 19 hours ago

Bem-vido!

O que você fez?

Solicitação POST para /instance/create, com o seguinte payload:

{
  "instanceName": "instancia",
  "qrcode": true
}

O header também foi configurado com a apikey segundo posto na doc:

apikey: teste1234

Sendo a mesma API key configurada no .env utilizado no cotâiner docker:

AUTHENTICATION_TYPE="apikey"
AUTHENTICATION_API_KEY="teste1234"

.env este sendo chamado no docker-compose.yml:

env_file:
      - .env

O que você esperava?

Criação da instância corretamente, já que é a mesma request que estava usando em versões anteriores a v2.1.1

O que vc observou ao invés do que esperava?

Erro de autorização, sendo que a chave API está correta.

Capturas de Tela/Vídeos

No response

Qual versão da API você está usando?

2.1.1

Qual é o seu ambiente?

Windows

Outras expecificações do ambiente

No response

Se aplicável, cole a saída do log

{
    "status": 401,
    "error": "Unauthorized",
    "response": {
        "message": "Unauthorized"
    }
}

Notas Adicionais

No response

lattaai1 commented 18 hours ago

Hello, I've fixed this issue!

This is what I've done: I have identified the issue in the authentication process for instance creation. The problem was in the apikey function of the auth.guard.ts file. The function was not properly handling the case when the API key was provided but did not match the global key. I've updated the logic to correctly authenticate requests for instance creation and fetching instances.

Here's a summary of the changes:

  1. Updated the apikey function in src/api/guards/auth.guard.ts to properly handle authentication for instance creation and fetching instances.
  2. Modified the error handling to throw more specific exceptions with clearer error messages.
  3. Improved the logic for checking the API key against the global key and instance-specific keys.

These changes should resolve the authentication issues you were experiencing when creating instances.

I also created pull request: https://github.com/EvolutionAPI/evolution-api/pull/1021

[!CAUTION]
Disclaimer: This fix was created by Latta AI and you should never merge before you check the correctness of generated code!


This bug was fixed for free by Latta AI - https://latta.ai/ourmission