Skip to content
Discussion options

You must be logged in to vote

The cleanest approach for per-user settings in Payload — without duplicating data or incurring expensive joins — is to store the relationship on the UserSettings document pointing back to the user, then use access control functions that check that field.

Recommended pattern

// collections/UserSettings.ts
import type { CollectionConfig } from 'payload'

export const UserSettings: CollectionConfig = {
  slug: 'user-settings',
  access: {
    create: ({ req }) => Boolean(req.user), // logged-in users only
    read: ({ req }) => {
      if (!req.user) return false
      // Only return docs where `owner` matches the logged-in user
      return {
        owner: { equals: req.user.id },
      }

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by MurzNN
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