trailsjs / sails-permissions

Comprehensive user permissions and entitlements system for sails.js and Waterline. Supports user authentication with passport.js, role-based permissioning, object ownership, and row-level security.
MIT License
418 stars 113 forks source link

permission&auth route, autoCreatedBy error #224

Open quantjin opened 8 years ago

quantjin commented 8 years ago

Hello, I'm using sails 0.12.1, sails-auth 2.1.3, sails-permissions 2.2.0

in my app, i have route set as

  'get /:account/journal': {
    controller: 'journal',
    action: 'index',
    skipAssets: true,
    locals: {
      layout: 'layouts/journal'
    }
  },

JournalController

module.exports = {
    index: function(req, res){
        res.view('journal');
    }
};

when i go to /myaccount/journal, it doesn't work per controller/action, i got 500 server error. Before i use sails permission, this part works.

In the console there's warning and error:

warn: Model [ journal ] not found in model cache
error: Sending 500 ("Server Error") response:
 TypeError: Cannot read property 'autoCreatedBy' of undefined
    at OwnerPolicy (\node_modules\sails-permissions\dist\api\policies\OwnerPolicy.js:21:34)
    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\express\lib\router\index.js:164:37)
    at param (\node_modules\sails\node_modules\express\lib\router\index.js:138:11)
    at param (\node_modules\sails\node_modules\express\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\express\lib\router\index.js:100:7)
    at callbacks (\node_modules\sails\node_modules\express\lib\router\index.js:167:11)
    at \node_modules\sails\lib\router\bind.js:187:7
    at module.exports (\node_modules\sails-permissions\dist\api\policies\AuditPolicy.js:22:3)
    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\express\lib\router\index.js:164:37)
    at param (\node_modules\sails\node_modules\express\lib\router\index.js:138:11)
    at param (\node_modules\sails\node_modules\express\lib\router\index.js:135:11)
[TypeError: Cannot read property 'autoCreatedBy' of undefined]

so just wondering if sails-auth, sails-permission already use some routes, i can find some in sails-auth, it seems it has no conflict with my own route:

route from sails-auth

module.exports.routes = {
  'post /register': 'UserController.create',
  'get /logout': 'AuthController.logout',

  'post /auth/local': 'AuthController.callback',
  'post /auth/local/:action': 'AuthController.callback',

  'get /auth/:provider': 'AuthController.provider',
  'get /auth/:provider/callback': 'AuthController.callback',
  'get /auth/:provider/:action': 'AuthController.callback'
};

also, what's the autoCreatedBy error about?

some update: if i only use sails-auth, it still works, it seems the issue is with sails-permissions

Thanks!

sposmen commented 8 years ago

Hi @JerryYangJin , I had the same issue, in the short time I managed it adding the route as first option inside routes.js... something like:

module.exports.routes = {
  'get /api/:id/journal': 'JournalController.index'
//...
};

I found that it was catching according to the order they were created. Check setting it as the first key in routes. Hope it helps!

joeinnes commented 8 years ago

Same issue on:

    "sails": "~0.12.3",
    "sails-auth": "^2.1.3",
    "sails-permissions": "^2.2.0",
richardwardza commented 8 years ago

Try creating a model with the name Journal?

The file should be in your model directory, Journal.js with the following content:

module.exports = {};