express - Passportjs local strategy never called only response without data -
i read issue of answers found doesn't work me. using passpotjs , local strategy in order make login routine. using express , reactjs well. when try call callback 'auth' module created passport local strategy, strategy never called. here code (the important part):
server
import express 'express'; import bodyparser 'body-parser'; import cookieparser 'cookie-parser'; import passport 'passport'; import react 'react'; import config './config' import routes './pages/containers/routes'; import auth './auth'; var clientapi = lisaclient.createclient(config.lisaclient); const lisaapp = express(); lisaapp.use(bodyparser.json()) lisaapp.use(bodyparser.urlencoded({ extended: false })) lisaapp.use(cookieparser()) lisaapp.use(expresssession({ secret: config.secret, resave: false, saveunitialized: false })) lisaapp.use(passport.initialize()) lisaapp.use(passport.session()) passport.use(auth.localstrategy); // here call strategy 'auth' module passport.deserializeuser(auth.deserializeuser); passport.serializeuser(auth.serializeuser); lisaapp.post('/login', (req, res) => { const validationresult = validateloginform(req.body); if (!validationresult.success) { return res.status(400).json({ success: false, message: validationresult.message, errors: validationresult.errors }); } // initial form validation ok return passport.authenticate('local', (err, token, userdata) => { console.log('response'); //always ok, no matter what. never call 'local'. })(req, res, next); }); lisaapp.listen(3000, () => { console.log('lisa listening 3000'); });
auth (module)
var localstrategy = require('passport-local').strategy; var lisaclient = require('pos_lisa-client'); var config = require('../config'); var clientapi = lisaclient.createclient(config.lisaclient); exports.localstrategy = new localstrategy((userclient, password, done) => { // never enter here, no matter if put console log console.log('strategy invoked'); clientapi.auth(userclient, password, (err, token) => { if (err) { return done(null, false, { message: 'data not found' }) } clientapi.getclient(userclient, (err, client) => { if (err) { return done(null, flase, { message: `an error ocurred: ${err.message}` }) } client.token = token return done(null, client) }) }) })
help me please! lot!
Comments
Post a Comment