Skip to content
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.

Adds ability to limit queries unless authenticated and authorized #229

Conversation

codingfriend1
Copy link
Contributor

@codingfriend1 codingfriend1 commented Jul 3, 2016

Often developers want to allow unauthenticated users or visitors to query data from a table but place restrictions on what type of data in the table is returned based on information in each row. This allows you to merge a restriction query into the query params to limit of the scope of what an unauthenticated user may search for.

Adds 3 hooks:

  • verifyOrRestrict({ restrict: {approved: true} })
  • populateOrRestrict({ restrict: {approved: true} })
  • hasRoleOrRestrict({roles: ['admin'], restrict: {approved: true} })

NOTICE: Currently does not filter direct ids through the get method

…trict to either add a query restriction to the query params when the user is not authenticated or authorized or else leave the query unrestricted.
@codingfriend1 codingfriend1 changed the title Adds ability to verifyOrRestrict, populateOrRestrict, or hasRoleOrRes… Adds ability to limit queries unless authenticated and authorized Jul 3, 2016
@codingfriend1
Copy link
Contributor Author

codingfriend1 commented Jul 5, 2016

Should now restrict direct id queries. However if using the memory service it's necessary to use

all: [function(hook) {
      if(hook.id) {
        hook.id = parseInt(hook.id, 10);
      }
}]

to make the hook.id an integer.

@ekryski
Copy link
Member

ekryski commented Jul 6, 2016

@codingfriend1 thanks for the PR! I will take a look at this tomorrow or Friday. 🍻

@ekryski
Copy link
Member

ekryski commented Jul 6, 2016

Actually this is totally awesome @codingfriend1! :shipit: Would you mind doing a PR to add these hooks to the docs? http://docs.feathersjs.com/authorization/bundled-hooks.html

@ekryski ekryski merged commit 43f1e40 into feathersjs-ecosystem:master Jul 6, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants