Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

permission&auth route, autoCreatedBy error #224

Open
quantjin opened this issue Mar 18, 2016 · 3 comments
Open

permission&auth route, autoCreatedBy error #224

quantjin opened this issue Mar 18, 2016 · 3 comments

Comments

@quantjin
Copy link

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
Copy link

sposmen commented May 17, 2016

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
Copy link

Same issue on:

    "sails": "~0.12.3",
    "sails-auth": "^2.1.3",
    "sails-permissions": "^2.2.0",

@richardwardza
Copy link

Try creating a model with the name Journal?

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

module.exports = {};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants