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.

Protect record from retrieval with simple password

default discord avatar
isa.ac2 years ago
3

What is the best way to go about creating a record that requires a simple password (no username) to retrieve? In essence, I am trying to create a webpage that is password-protected, populated by data pulled from Payload.

  • default discord avatar
    Payload-Bot2 years ago
  • default discord avatar
    minsomai2 years ago

    this can be handled outside from payloadcms.



    you can put auth middleware in the route itself, for the new page you are creating

  • discord user avatar
    jarrod_not_jared
    2 years ago

    We did have a plugin for this, but this was for an earlier version of payload.



    I will share the code, but please just use it as reference - try not to copy/paste it into your project.



    The idea is to set a cookie on the user so when they make a request you can check to see if the password in the cookie matches the password on the doc in a beforeRead operation. I would scope the cookie something like this

    password-protection-${collectionSlug}-${docID}

    https://github.com/payloadcms/plugin-password-protection/blob/main/src/index.ts#L71-L142
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.