1

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'
Mahesh B
  • 143
  • 2
  • 13

2 Answers2

2

if you want apply the policy to homepage

you must do it into the file route.js

 '/': {
    view: 'homepage',policy: 'isLoggedIn'
  }
David Zambrano
  • 650
  • 7
  • 13
0

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.

Ranjan
  • 448
  • 3
  • 13
  • Thanks for the response I added '/' in route.js with a controller to handle its working. But I was thinking if there is a way to handle policy for the views directly. – Mahesh B Nov 15 '16 at 07:44
  • @MaheshB No, there is no way you can handle policy for views directly. Atleast as of the current version. :) – Ranjan Nov 15 '16 at 12:26
  • @MaheshB Please accept the answer if its working fine – Ranjan Nov 20 '16 at 07:23