javascript - Sails.js create Index(root) Controller -


i wondering if there way have index controller index action. root login page , wanted detect if users session authenticated , if redirect them page.

is there specific notation how controller named? have tried indexcontroller.js , maincontroller.js. can't seem find in documentation this.

sails.js ver: 0.11.0

you need make controller , action yourself. there, set policy define access.

to make controller, run sails generate controller index in console.

then, open api/controllers/indexcontroller.js, make this:

module.exports = {   index: function (req, res) {     // add code display logged in view   } }; 

set config/routes.js this:

module.exports.routes = {   'get /': 'indexcontroller.index', }; 

afterwards, define policy has authentication logic. alternatively, can use included session authentication located @ api/policies/sessionauth.js assuming login action sets req.session.authenticated = true;. see the docs on policies more info.

lastly, connect policy action in config/policies.js:

module.exports.policies = {   indexcontroller: {     '*': false,                  // set default indexcontroller actions     index: 'sessionauth'         // or name of custom policy   } } 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -