Bootstrap admin users based on their email #2769

Closed
opened 2026-03-13 10:19:11 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @FredrikMorstad on GitHub (Jan 26, 2026).

Is this suited for github?

  • Yes, this is suited for github

I found the process of using known ids as admin nice, but i thought maybe using know emails to bootstrap admin users to be a little easier. Using an property like adminEmails would allow the better auth instance to set the admin role if this email is registered. This might be a property that only should be added if/when the email is verified

Describe the solution you'd like

export const auth = betterAuth({
  plugins: [
    adminPlugin({
        adminEmails: ["some@email.com",]
    }),
  ],
});

then this can be added as a hook before a register is complete similar to something one could do using afterEmailVerification for example:

    // this wont work as we cannot perform any admin actions without an admin user
   //  but this just shows the logic
    async afterEmailVerification(user, _) {
      if (user.role !== Role.Admin && adminEmails.includes(user.email)) {
        try {
          await auth.api.setRole({
            body: {
              userId: user.id,
              role: "admin",
              },
            },
            headers: await headers(),
          });
        } catch (error) {
        // log error
        }
      }
    },

Describe alternatives you've considered

I have only used the adminIDs property, but this requires the user to be created and then the id needs to be added as property during next startup

Additional context

No response

Originally created by @FredrikMorstad on GitHub (Jan 26, 2026). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I found the process of using known ids as admin nice, but i thought maybe using know emails to bootstrap admin users to be a little easier. Using an property like `adminEmails` would allow the better auth instance to set the admin role if this email is registered. This might be a property that only should be added if/when the email is verified ### Describe the solution you'd like ```ts export const auth = betterAuth({ plugins: [ adminPlugin({ adminEmails: ["some@email.com",] }), ], }); ``` then this can be added as a hook before a register is complete similar to something one could do using `afterEmailVerification` for example: ```ts // this wont work as we cannot perform any admin actions without an admin user // but this just shows the logic async afterEmailVerification(user, _) { if (user.role !== Role.Admin && adminEmails.includes(user.email)) { try { await auth.api.setRole({ body: { userId: user.id, role: "admin", }, }, headers: await headers(), }); } catch (error) { // log error } } }, ```` ### Describe alternatives you've considered I have only used the adminIDs property, but this requires the user to be created and then the id needs to be added as property during next startup ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 10:19:11 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 26, 2026):

Your feature request to bootstrap admin users based on their email seems interesting! The suggestion to utilize a property like adminEmails is a practical approach. This would streamline the admin role assignment process by checking registered emails, especially post-verification.

While there currently isn't an existing feature that fully supports your request, it's always great to bring this up on GitHub for further discussion! You might also want to implement a way to handle this in your application logic, similar to your provided example with afterEmailVerification.

If you need further assistance or want more specific insights related to Better Auth's capabilities, feel free to tag @bekacru or @ping__ for expert feedback. What other authentication features are you looking to implement?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Jan 26, 2026): Your feature request to bootstrap admin users based on their email seems interesting! The suggestion to utilize a property like `adminEmails` is a practical approach. This would streamline the admin role assignment process by checking registered emails, especially post-verification. While there currently isn't an existing feature that fully supports your request, it's always great to bring this up on GitHub for further discussion! You might also want to implement a way to handle this in your application logic, similar to your provided example with `afterEmailVerification`. If you need further assistance or want more specific insights related to Better Auth's capabilities, feel free to tag @bekacru or @ping__ for expert feedback. What other authentication features are you looking to implement? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@bytaesu commented on GitHub (Jan 28, 2026):

Hi @FredrikMorstad,

adminUserIds is meant to specify certain IDs that bypass admin roles (like a super admin). It's generally recommended to use authClient.admin.setRole(), and I think granting this permission via email is not appropriate

If you have further questions, feel free to reopen or mention me! 🙂

@bytaesu commented on GitHub (Jan 28, 2026): Hi @FredrikMorstad, `adminUserIds` is meant to specify certain IDs that bypass admin roles (like a super admin). It's generally recommended to use `authClient.admin.setRole()`, and I think granting this permission via email is not appropriate If you have further questions, feel free to reopen or mention me! 🙂
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2769