How can I apply a policy to homepage in Sails?

136 views Asked by At

I want to apply a policy that lets user to login to application. I written the code for policy. I want to apply this one to homepage also.

I tried below in policies.js but its not working on homepage.

'*' : 'isLoggedIn'
2

There are 2 answers

0
David Zambrano On

if you want apply the policy to homepage

you must do it into the file route.js

 '/': {
    view: 'homepage',policy: 'isLoggedIn'
  }
3
Ranjan On

I think you are not serving your homepage through a controller/action. Policies can only be applied to content which get served via controller/action.

From the documentation of Sails Policies :

Policies in Sails are versatile tools for authorization and access control-- they let you allow or deny access to your controllers down to a fine level of granularity.

It should start working once you serve the homepage via a controller.