check if is first install

default discord avatar
dnl.krmr
2 months 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 months ago

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

  • default discord avatar
    dnl.krmr
    2 months ago

    @kvist__ 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

  • discord user avatar
    jesschow
    Payload Team
    2 months ago

    Hi @dnl.krmr 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
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.