Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
648 views
in Technique[技术] by (71.8m points)

javascript - if (!options.algorithms) throw new Error('algorithms should be set'); Error: algorithms should be set

I started learning Nodejs and i am stuck somewhere in the middle. I installed a new library from npm and that was express-jwt, its showing some kind of error after running. Attached the code and the logs of the error, please help me out!

const jwt = require('jsonwebtoken');
require('dotenv').config()
const expressJwt =  require('express-jwt');
const User = require('../models/user');




exports.requireSignin =  expressJwt({ secret:  process.env.JWT_SECRET});

The below thing is the logs of the error.

[nodemon] starting `node app.js`
D:shubhprojNodejs
odeapi
ode_modulesexpress-jwtlibindex.js:22
  if (!options.algorithms) throw new Error('algorithms should be set');
                           ^

**Error: algorithms should be set**
    at module.exports (D:shubhprojNodejs
odeapi
ode_modulesexpress-jwtlibindex.js:22:34)
    at Object.<anonymous> (D:shubhprojNodejs
odeapicontrollersauth.js:64:26)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
 
question from:https://stackoverflow.com/questions/62665636/if-options-algorithms-throw-new-erroralgorithms-should-be-set-error-alg

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should add algorithms property to the jwt constructor.

Example;

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...