Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  146] [ 5]  / answers: 1 / hits: 22720  / 4 Years ago, tue, june 30, 2020, 12:00:00

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:shubhprojNodejsnodeapinode_modulesexpress-jwtlibindex.js:22
if (!options.algorithms) throw new Error('algorithms should be set');
^

**Error: algorithms should be set**
at module.exports (D:shubhprojNodejsnodeapinode_modulesexpress-jwtlibindex.js:22:34)
at Object.<anonymous> (D:shubhprojNodejsnodeapicontrollersauth.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)


More From » node.js

 Answers
12

You should add algorithms property to the jwt constructor.


Example;


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

[#50841] Wednesday, June 17, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
casandra

Total Points: 334
Total Questions: 93
Total Answers: 104

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
casandra questions
Thu, Feb 25, 21, 00:00, 3 Years ago
Mon, Jul 6, 20, 00:00, 4 Years ago
Thu, May 21, 20, 00:00, 4 Years ago
Tue, Sep 17, 19, 00:00, 5 Years ago
;