question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"TypeError: cb is not a function" when providing a native async function to options.secret

See original GitHub issue

I narrowed it down to the “isFunction” check at: https://github.com/auth0/express-jwt/blob/master/lib/index.js#L10. Since the async function is not correctly recognized as a function (Object.prototype.toString.call(object) returns [object AsyncFunction]), the provided “secret” callback is wrapped by the default callback provided by “wrapStaticSecretInCallback”.

The following options.secret function replicates the error:

async function secretProvider(req, header, payload, cb) {
   cb();
}

To fix the error, I would like to submit a PR to replace the isFunction check with the https://www.npmjs.com/package/lodash.isfunction package which detects async functions.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jfromaniellocommented, Apr 20, 2022

Sorry for the long delay, this is fixed in v7

1reaction
rebolytecommented, Jan 8, 2020

@KalleV @jfromaniello I just got bitten by this as well. Could we get one of the open PRs merged?

Read more comments on GitHub >

github_iconTop Results From Across the Web

async TypeError: cb is not a function - javascript
Someone can pass whatever they want or pass nothing at all (in which case cb will be undefined ). If you believe that...
Read more >
Practical Ways to Write Better JavaScript
Use Modern Features · async and await · let and const · Arrow => Functions · Spread Operator ... · Template Literals (Template...
Read more >
AWS Lambda context object in Node.js
This object provides methods and properties that provide information about the invocation, function, and execution environment. Context methods.
Read more >
How to convert between callbacks and Promises in Javascript
The other direction is to have a Promise-returning function (usually an async function) and you need to convert it to a callback-based one....
Read more >
Configuring Jest
Or a function returning an object: JavaScript; TypeScript. /** @returns {Promise<import('jest').Config>} */ module.exports = async () => {
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found