11

I used Sails.js + Passport.js authentication through websockets to bind passport.js methods for requests through websockets (using sockets.io) , but how should i add express-validator methods to ensure that all requests have methods from it

kobe24
  • 190
  • 1
  • 5
  • 16
  • Do you have any example code that you need express-validator to work with? – LJD Jul 24 '18 at 22:27
  • `updateMinimumAmount: (req, res) => { req.assert('schemeId', 'schemeId should be integer').notEmpty().isInt();` When this method is called from sockets instead making a http request , i am getting req.assert notfound but not the case if i call it with a http request – kobe24 Jul 25 '18 at 07:22
  • Can you post your code in question? – Harshal Yeole Jul 25 '18 at 07:58

1 Answers1

1

You can do it without using customMiddleware by adding 'express-validator' in the config/http.js:

order: [
      'startRequestTimer',
      'cookieParser',
      'session',
      'expressValidator',
      'bodyParser',
      'handleBodyParserError',
      'compress',
      'methodOverride',
      'poweredBy',
      '$custom',
      'router',
      'www',
      //'favicon',
      '404',
      '500'
],

expressValidator: require('express-validator')()

This should get you express validator and you can import and use it.

Hope it solves your query.

Harshal Yeole
  • 4,812
  • 1
  • 21
  • 43
  • But i don't think it will still be included in socket requests right , sockets request doesn't pass http.js for middleware , as i mentioned in the question the [link](https://stackoverflow.com/questions/17365444/sails-js-passport-js-authentication-through-websockets) helped me to include passport which i wrote in a new file called bindpassport_boot.js and kept it in app/boot . How can i do something similar for other libraries – kobe24 Jul 25 '18 at 08:39
  • Hi @Jack , I tried this solution and as i said above it doesn't have any effect . Any API call as http are getting the methods from express-validator but still API calls from sockets(using [socke.io](https://socket.io/)) still doesn't get the methods – kobe24 Jul 26 '18 at 10:23
  • How did you import them now? – Harshal Yeole Jul 26 '18 at 12:42
  • I shifted things to http requests and removed socket requests – kobe24 Jul 26 '18 at 12:50
  • Lets do some digging for the sockets and sails. – Harshal Yeole Jul 26 '18 at 12:53