"TypeError: cb is not a function" when providing a native async function to options.secret
See original GitHub issueI 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:
- Created 5 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry for the long delay, this is fixed in v7
@KalleV @jfromaniello I just got bitten by this as well. Could we get one of the open PRs merged?