NodeJS
(Solved) How to fix UnauthorizedError invalid algorithm?
August 30, 2020
1 min
While using package express-jwt
, I faced issue if (!options.algorithms) throw new Error(‘algorithms should be set’)
Below is stack trace of same
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)
Add algorithms property in expressJwt
constructor as follows
expressJwt({ secret: process.env.JWT_SECRET, algorithms: ['sha1', 'RS256', 'HS256'], })