не получается до конца прикрутить passport-jwt к express Код | const express = require('express'); const bodyParser = require('body-parser'); const passport = require('passport'); const app = express(); const PORT = process.env.PORT || 5000; app.use(bodyParser.urlencoded({extended:true})); app.use(bodyParser.json()); app.use(passport.initialize()); app.use(passport.session()); require('./middleware/passport')(passport); const routes = require('./settings/routes'); routes(app); app.listen(PORT, () => { console.log(`App listen on port ${PORT}`); })
|
Выдаёт ошибку на require('./middleware/passport')(passport); TypeError: require(...) is not a function вроде всё по документации делал во на всякий случай содержимое /middleware/passport.js Код | const JwtStrategy = require('passport-jwt').Strategy; const ExtractJwt = require('passport-jwt').ExtractJwt; const db = require('./../settings/db'); const config = require('./../config'); const options = { jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), secretOrKey: config.JWT } module.experts = passport => { passport.use( new JwtStrategy(options, (payload, done) => { try { db.query("SELECT `user_id`, `email` FROM `users` WHERE `user_id` = '" + payload.userId + "'", (error, rows, fields) => { if (error) { console.log(error); } else { if (user) { done(null, user); } else { done(null, false); } } }); } catch(e) { console.log(e) } }) ); }
|
В чём прблемма понять не могу
|