Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

hide sensitive data from relationship field

default discord avatar
dnl.krmr2 years ago
8

In my collections I'm having a field called "author", having a relationship to my users table and per default set to user.id



But when querying the field using the rest api I'm getting the complete data from the users collections including all fields and also sensitive Data such as the api key.


The users name would be completely sufficient.



Can I change this anywhere? Some best practices?

  • default discord avatar
    abdullahasad72532 years ago
  • default discord avatar
    dnl.krmr2 years ago

    Good point 👍


    I'll give it a try 😄



    @692287123382075393

    thx, worked as expected

  • default discord avatar
    abdullahasad72532 years ago

    how did you do could you share some dummy code

  • default discord avatar
    dnl.krmr2 years ago
    @692287123382075393

    I'll share it as I finished it.


    Had some correlation with other data/fields

  • default discord avatar
    brianjm2 years ago
    @692287123382075393

    Here's an example. If you don't want the field data to show at all in the response. set it to

    undefined

    like

    doc.apiKey = undefined

    .

    https://github.com/payloadcms/payload/discussions/4400#discussioncomment-8547663
  • default discord avatar
    abdullahasad7253last year

    i wanted to hide data from the res rather than the actual db

  • default discord avatar
    brianjmlast year

    That is what this does.

  • default discord avatar
    abdullahasad7253last year

    Yes solved thanks

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.