balderdashy / angularSails

AngularJS bindings for Sails. http://angularjs.org
MIT License
184 stars 36 forks source link

server error 500 req.isAuthenticated is not a function #75

Open quantjin opened 8 years ago

quantjin commented 8 years ago

Hello, I'm using passport to do authorization, i'm getting below error while using $sailsSocket

is there anyway to authorize $sailsSocket requests?

thanks!

Error from console:

error: Sending 500 ("Server Error") response:
 TypeError: req.isAuthenticated is not a function
    at module.exports (\api\policies\sessionAuth.js:1
4:11)
    at routeTargetFnWrapper (\node_modules\sails\lib\
router\bind.js:179:5)
    at \node_modules\sails\lib\router\bind.js:244:14
    at callbacks (\node_modules\sails\node_modules\ex
press\lib\router\index.js:164:37)
    at param (\node_modules\sails\node_modules\expres
s\lib\router\index.js:138:11)
    at param (\node_modules\sails\node_modules\expres
s\lib\router\index.js:135:11)
    at pass (\node_modules\sails\node_modules\express
\lib\router\index.js:145:5)
    at nextRoute (\node_modules\sails\node_modules\ex
press\lib\router\index.js:100:7)
    at callbacks (\node_modules\sails\node_modules\ex
press\lib\router\index.js:167:11)
    at \node_modules\sails\lib\router\bind.js:187:7
    at module.exports (\node_modules\sails\lib\hooks\
cors\clear-headers.js:14:3)
    at routeTargetFnWrapper (\node_modules\sails\lib\
router\bind.js:179:5)
    at callbacks (\node_modules\sails\node_modules\ex
press\lib\router\index.js:164:37)
    at param (\node_modules\sails\node_modules\expres
s\lib\router\index.js:138:11)
    at pass (\node_modules\sails\node_modules\express
\lib\router\index.js:145:5)
    at nextRoute (\node_modules\sails\node_modules\ex
press\lib\router\index.js:100:7) [TypeError: req.isAuthenticated is not a functi
on]

policies\sessionAuth.js

module.exports = function(req, res, next) {

  // User is allowed, proceed to the next policy,
  // or if this is the last policy, the controller
  if (req.isAuthenticated()) {
    return next();
  }

  // User is not allowed
  // (default res.forbidden() behavior can be overridden in `config/403.js`)
  //return res.forbidden('You are not permitted to perform this action.');
  return res.redirect('/auth/signin/');
};

config\policies.js

module.exports.policies = {

  /***************************************************************************
  *                                                                          *
  * Default policy for all controllers and actions (`true` allows public     *
  * access)                                                                  *
  *                                                                          *
  ***************************************************************************/

  '*': 'sessionAuth',

  'auth': {
    '*': true
  }

  /***************************************************************************
  *                                                                          *
  * Here's an example of mapping some policies to run before a controller    *
  * and its actions                                                          *
  *                                                                          *
  ***************************************************************************/
    // RabbitController: {

        // Apply the `false` policy as the default for all of RabbitController's actions
        // (`false` prevents all access, which ensures that nothing bad happens to our rabbits)
        // '*': false,

        // For the action `nurture`, apply the 'isRabbitMother' policy
        // (this overrides `false` above)
        // nurture  : 'isRabbitMother',

        // Apply the `isNiceToAnimals` AND `hasRabbitFood` policies
        // before letting any users feed our rabbits
        // feed : ['isNiceToAnimals', 'hasRabbitFood']
    // }
};
quantjin commented 8 years ago

Hello, I found below in the document

it looks like the setup for authorization, but what should I put there if I'm using passport?

module.run(function($sailsSocket) {
  $sailsSocket.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w'
});
outOFFspace commented 8 years ago

Same problem