ginad
ginad

Reputation: 1973

multiple controller in one policy in sails

In the documentation I saw that we can define multiple policies to a single controller but is it possible define multiple controllers in an array to use one policy?

Example:

['ControllerOne', 'ControllerTwo'] : 'isAuthenticated'

Thanks

Upvotes: 1

Views: 541

Answers (1)

sgress454
sgress454

Reputation: 24948

No, policies are defined on a per-controller basis. However, you can also define a wildcard policy, so if you find that most of your controllers use a policy, you could define that in the wildcard and then take care of the controllers that don't require it separately:

module.exports = {

    // Most controllers use "isAuthenticated" policy...
    '*': 'isAuthenticated',

    // But not PublicController, which is open to everyone...
    'PublicController': {
        '*': true
    },

    // And not StaticController, except for the "uploads" method.
    'StaticController': {
        '*': true,
        'uploads': 'isAuthenticated'
    }

}

Upvotes: 2

Related Questions