[GH-ISSUE #324] The username field is mandatory when creating a new user through the admin #8220

Closed
opened 2026-04-13 03:19:13 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @0xPratikPatil on GitHub (Oct 24, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/324

If the developer uses the username field in the project, it must appear when creating a new user, along with email, password, name, and role.

Reference: client.admin.createUser()

Originally created by @0xPratikPatil on GitHub (Oct 24, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/324 If the developer uses the username field in the project, it must appear when creating a new user, along with email, password, name, and role. Reference: client.admin.createUser()
GiteaMirror added the locked label 2026-04-13 03:19:13 -05:00
Author
Owner

@lanzclintonv commented on GitHub (Nov 7, 2024):

I encountered the same issue and found a workaround using data.

await authClient.admin.createUser({
          name: "Admin for Testing",
          email: "admin@example.com",
          password: "password1234",
          role: "admin",
          data: {
            username: "admin",
          },

This is a sample on how you can append the username.

<!-- gh-comment-id:2461301411 --> @lanzclintonv commented on GitHub (Nov 7, 2024): I encountered the same issue and found a workaround using data. ``` await authClient.admin.createUser({ name: "Admin for Testing", email: "admin@example.com", password: "password1234", role: "admin", data: { username: "admin", }, ``` This is a sample on how you can append the username.
Author
Owner

@0xPratikPatil commented on GitHub (Nov 7, 2024):

OK, thanks for providing the solution. This is great if the user schema has other data fields to manipulate.

<!-- gh-comment-id:2461329078 --> @0xPratikPatil commented on GitHub (Nov 7, 2024): OK, thanks for providing the solution. This is great if the user schema has other data fields to manipulate.
Author
Owner

@Bekacru commented on GitHub (Nov 17, 2024):

No plans to infer types in the admin plugin. It’s a hacky workaround and heavy on ts server, passing data works well enough and is secure enough, as it can only be done by admins.

<!-- gh-comment-id:2480989777 --> @Bekacru commented on GitHub (Nov 17, 2024): No plans to infer types in the admin plugin. It’s a hacky workaround and heavy on ts server, passing data works well enough and is secure enough, as it can only be done by admins.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8220