Coder Social home page Coder Social logo

Public Role Usage about sails-permissions HOT 4 OPEN

trailsjs avatar trailsjs commented on August 15, 2024 2
Public Role Usage

from sails-permissions.

Comments (4)

dottodot avatar dottodot commented on August 15, 2024

Are you able to provide any information on this. At present it's unusable if it's not possible to grant public/anonymous users access to certain things.

from sails-permissions.

dottodot avatar dottodot commented on August 15, 2024

OK I've realised what's happening now. The sessionAuth policy is requiring the user to be logged in so no matter what permissions are set up they must be logged in first. This can be fixed by allowing access to actions through policies.js but this seems to defeat some of the purpose of this system.

Not sure if this would work, but I've seen this method used elsewhere, is users that are not logged would be assigned to a default anonymous user account, which would have a role of public only. I believe this would then make it possible to use the public role to grant access for anon users.

I think all that would be required is to include a default anon user account along with the default admin one and then changing the sessionAuth policy so that rather returning a 403 it assigns them as the anon user.

// api/policies/sessionAuth.js
module.exports = function(req, res, next) {
  if (req.session.authenticated) {
    return next();
  } else {
    User.findOne({username: 'anon'}).then(function(user){
      req.user = user;
      return next();
    });
  }
};

Obviously I can implement this myself but as there is a default public role it probably should be included. Also I'm not 100% sure if this method will cause any undesirable issues.

from sails-permissions.

ksylvan avatar ksylvan commented on August 15, 2024

πŸ‘

from sails-permissions.

yadavji83 avatar yadavji83 commented on August 15, 2024

Ran into the same problem. I thought all visitors will be treated as public user. Also your workaround looks ok but it wont help in debug. As the requestlog will show all the public users as anon and it will be impossible to track down a particular request. There should be a method of creating a separate request id for each request and assign that as username with public role.

Any input from developers!

from sails-permissions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.