Skip to content

Access Control for a collection when authenticated against specific collection only #185

Answered by denolfe
ryanlanciaux asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @ryanlanciaux, thanks for the question. You were definitely on the right track. We could probably explain this more and add examples of this in the documentation. Here is an example of doing what you describe:

You can see from the code that if the user is in the admins collection it will return true, indicating access to all. However, if the user is in the users collection, a query constraint is returned that will return only documents with that user's id.

const userAccess = ({ req: { user } }) => {
  if (user) {
    if (user.collection === 'admins') {
      return true;
    }

    if (user.collection === 'users') {
      return {
        id: {
          equals: user.id,
        },

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ryanlanciaux
Comment options

Answer selected by ryanlanciaux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants