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.

check if is first install

default discord avatar
dnl.krmr2 years ago
3

In my users collections I got a field called "isSuperAdmin". This field can only be set by another super admin


But at first install there is no user available.



Is there a possibility to check if I'm running payload for the first time?

  • default discord avatar
    kvist__2 years ago

    if you are running payload for the first time, it should ask you to create a user

  • default discord avatar
    dnl.krmr2 years ago
    @190890421243740160

    yes, I know. But I only display some fields within my user configuration page if the user is an admin. And at first-install I want to create an admin. So I have to check if it is the first install page to ignore checks

  • default discord avatar
    jessrynkar2 years ago

    Hi

    @775820309730557982

    you can achieve this by adding a

    beforeChange

    hook to your users collection, this hook would check if any users exist, if it is the first user then assign your admin role.



    Here is an example:

    https://github.com/payloadcms/template-website/blob/main/src/collections/Users/hooks/ensureFirstUserIsAdmin.ts
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.