Skip to content
This repository was archived by the owner on Aug 13, 2021. It is now read-only.
This repository was archived by the owner on Aug 13, 2021. It is now read-only.

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

@quantjin

Description

@quantjin

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']
    // }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions