我在 LocalStrategy 回调函数中写了 console.log,但它从未被调用。我使用 Sequelize 作为 ORM(MySQL)。
passport.js
const LocalStrategy = require('passport-local').Strategy
const passport = require('passport')
const bcrypt = require('bcrypt')
const UrunModel = require('../models/Urun')
console.log('File is Called') // If my require is wrong. But this log worked.
passport.use(new LocalStrategy({
usernameField: 'mail',
passwordField: 'pw1'
},
(username, password, done) => {
console.log('Worked!') // Never Called
UrunModel.findOne({
where : {
UrunName : 'testuser',
UrunDesc : '123456'
}
})
}
));
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
});
});
index.js
const session = require('express-session');
const bodyParser = require('body-parser')
const urlencoded = bodyParser.urlencoded({extended:false})
const passport = require('passport')
app.use(session({
secret: 'keyboardSecrIncKey',
resave: false,
saveUninitialized: true,
}))
app.use(passport.initialize())
app.use(passport.session())
require('./config/passport') //require my passport.js
app.post('/test',(req,res,next) => {
passport.authenticate('local',{
successRedirect: '/worked',
failureRedirect: '/notworked'
})(req,res,next)
})
它将我重定向到 '/notworked' URL。我看了3或4个视频,但我的代码几乎相同。
我在哪里失败了?请解释一下我的错误。