Sails passport js integration using sails as REST API

I am trying to use passport js for authentication in my local mysql database. I am using postman extension to test the application. I am sending two fields i.e. username and password for authentication. When any one of the field is blank then response is shown in json format as

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

But when I pass values for both the fields I get 500 internal server error.

error: Sending 500 ("Server Error") response: TypeError: Cannot read property 'message' of undefined at d:\Test\api\controllers\AuthController.js:25:23 at Strategy.strategy.error (d:\Test\node_modules\passport\lib\middleware\authenticate.js:333:18) at Strategy.authenticate (d:\Test\node_modules\passport-local\lib\strategy.js:94:17) at attempt (d:\Test\node_modules\passport\lib\middleware\authenticate.js:341:16) at authenticate (d:\Test\node_modules\passport\lib\middleware\authenticate.js:342:7) at Object.module.exports.login (d:\Test\api\controllers\AuthController.js:37:7) at bound (C:\Users*\AppData\Roaming\npm\node_modules\sails\node_modules\lodash\dist\lodash.js:729:21) at routeTargetFnWrapper (C:\Users*\AppData\Roaming\npm\node_modules\sails\lib\router\bind.js:179:5) at callbacks (C:\Users*\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:164:37) at param (C:\Users*\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:138:11) at pass (C:\Users*\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:145:5) at nextRoute (C:\Users*\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:100:7) at callbacks (C:\Users*\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:167:11) at C:\Users*\AppData\Roaming\npm\node_modules\sails\lib\router\bind.js:187:7 at alwaysAllow (C:\Users*\AppData\Roaming\npm\node_modules\sails\lib\hooks\policies\index.js:207:11) at routeTargetFnWrapper (C:\Users*\AppData\Roaming\npm\node_modules\sails\lib\router\bind.js:179:5) [TypeError: Cannot read property 'message' of undefined]**

Below is my 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 am using the below model for 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 which contains the username and password also has other fields like country. Is there any way I can authenticate it using passport.

Category:mysql Views:37 Time:2019-03-21

Related post

  • Can DAG be used with the REST API? 2013-12-11

    It appears that DAG is only available as a hosted service. How do I test my code integration programmatically through the REST API for the following methods? addSiteAccount1 getMFAResponseForSite putMFAResponseForSite Is there a way to do this with r

  • Upload SLD's graphic using geoserver's REST API 2010-09-06

    How to upload SLD's graphic using geoserver's REST API. I have managed to upload SLD's style file but I do not see any possibility to upload graphic which style is using. --------------Solutions------------- GeoServer's REST API does not support uplo

  • Facebook session key using the old rest api 2010-10-11

    I know this should be on the facebook developer site but I can't seem to register. Anyway I'm using the new api to obtain a access token when connecting to the xmpp chat server but this access token doesn't work; I have to use the old rest api's 'ses

  • Is it hacky to manually construct JSON and manually handle GET, POST instead of using a proper RESTful API for AJAX functionality? 2011-01-07

    I started building a Django app, but this probably applies to other frameworks as well. In Backbone.js methods that call the server (fetch(), create(), destroy(), etc.), should you be using a proper RESTful API such as one provided by Tastypie or Dja

  • IE9 error SEC7111 ("HTTPS security is compromised") when using the Facebook REST API 2011-03-16

    I'm the author of a Wordpress plugin that allows users to login to their blogs with Facebook; it uses the old REST API to introduce the login button. Typically, including the API is done via the following: <script type="text/javascript" src="http:

  • How to secure the RESTful webservices created using Springs's REST Api? 2011-05-20

    We have a Spring web application created using Spring MVC 3.0 In the same application, we have created RESTful web services using Springs's REST API. Now we need to secure those web services. How do we do this in spring? Can we use spring security fo

  • Using the Nexus rest API to get latest artifact version for given groupid/artficatid 2011-10-27

    I am trying to use the nexus REST api to get the latest version of a maven artifact. I am able to browse to the specific version I am looking for using http://repo.local/service/local/data_index?a=local-turbogears-server&from=0&g=com.turbo

  • Why use django related REST API packages for non ORM calls? 2012-02-23

    What are the pros and cons for using django related REST API packages such as tastypie, piston or django-rest for non-ORM calls over simply using views? --------------Solutions------------- I don't think its really a question of whether the API resou

  • Creating a folder in my personal Locker using Desire2Learn's REST APIs 2012-04-27

    How do I create a new folder (called "test") in my personal locker using Desire2Learn's REST API? I've tried this request, but it doesn't work: POST /d2l/api/le/1.0/locker/mylocker/?x_a={appID}&x_c={appSig}&x_b={myUserID}&x_d={myUserSig}

  • Uploading to a folder in my personal Locker using Desire2Learn's REST APIs 2012-04-27

    How do I upload a file to my locker using Desire2Learn's REST API? The server returns status code 200 but "An unexpected error has occurred" POST /d2l/api/le/1.0/locker/mylocker/?x_a={appID}&x_c={appSig}&x_b={myUserID}&x_d={myUserSig}

  • Does Payflow pro can be used through new REST APIs or they are two different service? 2013-06-06

    I am researching how to move Classic APIs Payflow pro to used new REST APIs. Does Payflow pro can be used through new REST APIs or they are two different service? How to get REST API CREDENTIALS for a Merchant account or add "service" in PayPal Manag

  • How to use OpenID in RESTful API? 2009-12-02

    I'm building Pylons-based web application with RESTful API, which currently lacks any authentication. So I'm going to implement that and in order to avoid all the trouble and caution with storing user passwords, I'd like to use OpenID for authenticat

  • What is the best way to use old Facebook REST API and new Facebook Graph API on the same webpage? 2010-10-14

    The existing page has code to work with the old REST API: jQuery(document).ready( function() { FB_RequireFeatures(["Connect", "XFBML"], function() { FB.init('12345678ABCDEF','/xd_receiver.html', {ifUserNotConnected: fb_user_not_connected}); // real k

  • Can I search for issues (wildcard) using the Redmine REST API? 2011-02-14

    I know you can query for issues using known values (i.e. project_id=1), but is it possible to query for issue via wildcard search (i.e. issue_subject=*wildcard*, or issue_description=*wildcard*)? The REST API documentation doesn't seem to indicate th

  • Manipulating POST data to work with Symfony2 forms when used in a REST API 2012-02-16

    Background: I am writing a RESTful API on symfony. I want the client to be able to post to a url using the content type application/json and post a json object of form that the controller action is looking for. Im using a pretty basic controller setu

  • Creating a user/entity using Janrain Capture RESTful API 2012-04-22

    Is it possible to create a user/entity using Janrain Capture without using the built in registration widgets, but using the RESTful API? I am hoping to ask a user a number o

  • Timestamp range when using Desire2Learn's REST APIs 2012-04-26

    What's the allowable range for discrepancies between a caller's timestamp value and the back-end service's time when making calls to Desire2Learn's Valence REST APIs? --------------Solutions------------- The timestamp threshold is narrow, but, if you

  • Creating an event-invite using the old REST API 2011-01-16

    I cannot do the following with the Graph API, so I'm trying to do it with the old REST API, but without any success... No error message, but also no invite. $restApi = $facebook->api(array( 'method' => 'events.invite', 'eid' => $eid, 'uids'

  • How to use facebook's REST API call "LiveMessage.Send" 2011-05-16

    This might be a "possible" duplicate (I've read a few answers on here and none caught my eye :/) in which case I apologize! However I've been banging my head for 3 days now trying to get this right! I have got a normal Canvas app setup (because FBML

  • Get country code using Bing Maps REST API 2012-10-12

    I am a WP7 developer. I have longitude and latitude of a location and getting complete information defined by the coordinate ie longitude and latitude by using Bing maps API,-95.712891?o=json

  • Using Google Search REST API in Ruby 2010-04-20

    I'm trying to do a google search using Ruby, and print the 1st 3 results. Could anyone point me to a sample code? I'm unable to find it. --------------Solutions------------- The gem googleajax is there for that: require 'googleajax' GoogleAjax.refere

  • What is the best web language/framework to use with a REST API and JSON? 2011-01-14

    I am about to create a web application and need some advice. The basics of the app (without giving too much away) is there will be some Javascript on a page sending back various information to a REST server through JSON to be stored in a database. Is

  • Using the Teamcity REST API to get a build Log 2012-01-30

    Say I have a specific build, such as : How would I get the build log of that build? --------------Solutions------------- Just download http://your.teamcity.server/httpAuth/downloadBui

  • Using Artifactory's REST API to deploy jar file 2012-02-09

    Given this api documentation, how would I use HTTPBuilder and Groovy to construct my query? I've tried multiple things but I'm not getting it right. def http = new HTTPBuilder() http.request('http://artifactory:8888/libs-snapshot-local/my/jar/1.0/tes

Copyright (C), All Rights Reserved.

processed in 0.116 (s). 11 q(s)