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.

Get client IP Address

default discord avatar
eduh2 years ago
7

Hello, I want to make a verification to make sure an user haven't created any entry in collection by custom endpoint.



Other solutions than

request._peername

?

  • default discord avatar
    notchr2 years ago
    @244206138445398027

    Is IP the best way to prevent entry duplication?



    You have access to the {user} object in a custom endpoint, is that not sufficient?



    Or is it like a public endpoint?

  • default discord avatar
    eduh2 years ago

    I want it because I want to avoid request spamming



    it's a public endpoint

  • default discord avatar
    notchr2 years ago

    There is rate limiting implemented by default by IP



    500 requests / 15min per IP



    You can adjust those settings on the payload main config



    https://payloadcms.com/docs/production/preventing-abuse#rate-limiting-requests

    Let me know if that doesn't solve your issue

  • default discord avatar
    eduh2 years ago

    No, I really want the IP in the request😁

  • default discord avatar
    notchr2 years ago

    Are you running behind a proxy?

  • default discord avatar
    eduh2 years ago

    in production on cloudflare



    one solution is the cloudflare header, not tested tet



    yet*

  • default discord avatar
    notchr2 years ago
    @244206138445398027

    So if its your own proxy, you can usually use

    'x-forwarded-for'

    but im not sure the accuracy of that if its through cloudflare



    You would need to adjust your nginx config if its not your own proxy as well

    proxy_set_header X-Forwarded-For $remote_addr;
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.