balderdashy / balderdashy/sails

Invalid policy setting for `/api/dogs`: `inRole("dogs")` does not correspond to any of the loaded policies.

Open
#6,901 7 comments 0 reactions 0 assignees View on GitHub
helpful info or workaround question
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Node version: 10.15.-
sails: ^1.2.3,
sails-hook-orm: ^2.1.1,
sails-hook-sockets: ^2.0.0,
sails-mysql: ^1.0.1
Development environment


Any clue about this Error:

```
Invalid policy setting for `/api/dogs`: `inRole("dogs")` does not correspond to any of the loaded policies.
```

I have a file `/api/policies/inRole.js` that looks like this:

```
module.exports = (role) => (req, res, next) => {
if (req.user && req.user.inRole(role)) {
next();
}

res.status(403).json({message: `No access to the endpoint ${req.path}` });
};
```

And in the file `config/policies.js` I have this:
```
module.exports.policies = {
'/api/dogs': 'inRole("dogs")'
};
```

I don't understand what I am doing wrong that would produce this error.

Contributor guide

Open the contributing guide

Research direction

Start with config/policies.js and api/policies/inRole.js, then inspect how Sails loads and validates policy settings for /api/dogs. Reproduce the configuration with the listed Sails and Node versions; done means the policy is recognized and the endpoint's authorization behavior can be exercised without the invalid-policy error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, authorization, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.