Skip to content

Access based on originalDoc data #470

Answered by jmikrut
chladog asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @chladog — question for you.

When you say:

Now I need to write an access functions that will resolve true only if user.id === doc.owner. I stuck here as access functions don't pass doc data.

Do you want to use field hooks, or collection-level hooks here?

If collection level, this is actually super easy. In access control, you can return a query constraint to restrict which documents that a user can perform actions against.

Here's an example of how we would normally do something like this:

const adminOwnerAccess = ({ req: { user } }) => {
  // If user is admin, return true
  if (user && user.roles.includes('admin')) {
    return true;
  }

  // If there is a user, return a query cons…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@chladog
Comment options

@jmikrut
Comment options

@chladog
Comment options

Answer selected by chladog
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