1
resposta

Erro ao usar o Token

Baixei o projeto da aula 3, mas as rotas que usam o token para autenticar está dando o erro abaixo, as rotas de criar usuário e login estão funcionando.

[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
App listening on port 3000
(node:11964) UnhandledPromiseRejectionWarning: ReferenceError: InvalidArgumentError is not defined
    at adiciona (C:\Users\switek\Desktop\blog-do-codigo-aula-3\src\posts\posts-controlador.js:11:27)
    at Layer.handle [as handle_request] (C:\Users\switek\Desktop\blog-do-codigo-aula-3\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\switek\Desktop\blog-do-codigo-aula-3\node_modules\express\lib\router\route.js:137:13)
    at C:\Users\switek\Desktop\blog-do-codigo-aula-3\src\usuarios\middlewares-autenticacao.js:45:16
    at Strategy.strategy.success (C:\Users\switek\Desktop\blog-do-codigo-aula-3\node_modules\passport\lib\middleware\authenticate.js:219:18)
    at verified (C:\Users\switek\Desktop\blog-do-codigo-aula-3\node_modules\passport-http-bearer\lib\strategy.js:126:10)
    at Strategy._verify (C:\Users\switek\Desktop\blog-do-codigo-aula-3\src\usuarios\estrategias-autenticacao.js:52:9)
(node:11964) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:11964) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
1 resposta

Oi, Andre!

Parece que houve algum problema com os imports do projeto no posts-controlador.js... Fiz uma correção no repositório e acho que agora está tudo certo!

Você poderia baixar novamente e ver se o erro se repete?

Abraços

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software