HomeTutorsContact

(Solved) How to fix error algorithms should be set express-jwt?

By Gulshan Saini
Published in NodeJS
August 28, 2020
1 min read

While using package express-jwt, I faced issue if (!options.algorithms) throw new Error(‘algorithms should be set’)

Below is stack trace of same

Error

if (!options.algorithms) throw new Error('algorithms should be set');
                           ^
Error: algorithms should be set
    at module.exports (/server/node_modules/express-jwt/lib/index.js:22:34)
    at Object.<anonymous> (/server/controllers/auth.js:158:24)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/server/routes/auth.js:3:47)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)

Solution

Add algorithms property in expressJwt constructor as follows

expressJwt({
  secret: process.env.JWT_SECRET,
  algorithms: ['sha1', 'RS256', 'HS256'],
})

Tags

#express#express-jwt
Previous Article
(Solved) Unexpected end of JSON input while parsing near '...'?

Related Posts

NodeJS
(Solved) How to fix UnauthorizedError invalid algorithm?
August 30, 2020
1 min
Gulshan Saini

Gulshan Saini

Fullstack Developer

Topics

Angular
JavaScript
ReactJS
Typescript

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.
© 2021, All Rights Reserved.

Quick Links

Contact UsBrowserCSSPythonPuppeteer

Social Media