mysql - Sails passport js integration using sails as REST API -


i trying use passport js authentication in local mysql database. using postman extension test application. sending 2 fields i.e. username , password authentication. when 1 of field blank response shown in json format

{   "message": "missing credentials",   "user": false } 

but when pass values both fields 500 internal server error.

error: sending 500 ("server error") response: typeerror: cannot read property 'message' of undefined @ d:\test\api\controllers\authcontroller.js:25:23 @ strategy.strategy.error (d:\test\node_modules\passport\lib\middleware\authenticate.js:333:18) @ strategy.authenticate (d:\test\node_modules\passport-local\lib\strategy.js:94:17) @ attempt (d:\test\node_modules\passport\lib\middleware\authenticate.js:341:16) @ authenticate (d:\test\node_modules\passport\lib\middleware\authenticate.js:342:7) @ object.module.exports.login (d:\test\api\controllers\authcontroller.js:37:7) @ bound (c:\users*\appdata\roaming\npm\node_modules\sails\node_modules\lodash\dist\lodash.js:729:21) @ routetargetfnwrapper (c:\users*\appdata\roaming\npm\node_modules\sails\lib\router\bind.js:179:5) @ callbacks (c:\users*\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:164:37) @ param (c:\users*\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:138:11) @ pass (c:\users*\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:145:5) @ nextroute (c:\users*\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:100:7) @ callbacks (c:\users*\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:167:11) @ c:\users*\appdata\roaming\npm\node_modules\sails\lib\router\bind.js:187:7 @ alwaysallow (c:\users*\appdata\roaming\npm\node_modules\sails\lib\hooks\policies\index.js:207:11) @ routetargetfnwrapper (c:\users*\appdata\roaming\npm\node_modules\sails\lib\router\bind.js:179:5) [typeerror: cannot read property 'message' of undefined]**

below authcontroller

var passport=require('passport');    login:function(req,res){      passport.authenticate('local', function(err, user, info) {        if ((err) || (!user)) {          return res.send({           message:info.message,           user: user         });       }       req.login(user, function(err) {         if (err) res.send(err);         return res.send({           message:"user loged in",//info.message,           user: user         });       });      })(req, res);    } }; 

i using below model testing

module.exports = {    tablename: 'users',   connection:'testdb',   autocreatedat:false,   autoupdatedat:false,    attributes: {     username:{         type:'string',         required:true       },     password:{       type:'string',       required:true     },     tojson: function() {       var obj = this.toobject();       delete obj.password;       return obj;     }   } }; 

the table contains username , password has other fields country. there way can authenticate using passport.

did sixth step of link

module.exports.http = {   middleware: {     passportinit    : require('passport').initialize(),     passportsession : require('passport').session(),      order: [       'startrequesttimer',       'cookieparser',       'session',       'passportinit',       'passportsession',       'myrequestlogger',       'bodyparser',       'handlebodyparsererror',       'compress',       'methodoverride',       'poweredby',       'router',       'www',       'favicon',       '404',       '500'     ],   } }; 

maybe want see sails-hook-sanpassport, easy , fast


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -