dovahkiin
dovahkiin

Reputation: 718

Securing a page with using passport.js, sails.js and sails generate auth

How do I secure a page so I cannot be accessed by a non authenticated user? I've read the answer to this question but I haven't been able to correctly secure a page with sails generate auth for sails.js, using passport.js.

Thanks.

Upvotes: 1

Views: 146

Answers (1)

Alexis N-o
Alexis N-o

Reputation: 3993

When you generated your application, a sessionAuth policy must have been created. This is an example policy that is created when you generate a sails app. It is not part of sails-generate-auth.

To use it for your secured routes, write your configuration in the config/policies.js file.

SecuredController: {
    // Apply the `sessionAuth` policy for all of SecuredController's actions
    '*': 'sessionAuth',
};

sails-generate-auth will populate req.session.authenticated during the login so the sessionAuth policy will behave as expected if you correctly configured your config/policies.js file.

Upvotes: 2

Related Questions