Skip to content
Discussion options

You must be logged in to vote

Hey @MurzNN this is a great question! I've run into this myself a few times.

My suggested approach would be something like this:

// Collection-level access returns a where constraint for ownership:
access: {
  update: ({ req: { user } }) => {
    if (!user) return false
    if (user.roles?.includes('admin')) return true
    // Returns a query constraint — only matches docs where owner === current user
    return {
      owner: { equals: user.id },
    }
  },
},

Then you can apply that access to each of your fields:

{ name: 'owner',     type: 'relationship', access: { update: adminOnly } },
{ name: 'createdBy', type: 'relationship', access: { update: adminOnly } },
// ... repeat for all r…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

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

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