I'm trying to seed a user into the database during my setup process
Is there a way to seed a user directly into the database using Better Auth without relying on the request context(cookies)?
const superAdminResult = await auth.api.signUpEmail({
body: {
email: "admin@example.com",
password: "kjk2nduhu23dsa2",
name: "ADMIN",
}
})
12 Replies
Its a massive pita. You need to figure out password hashing using argon2 and scrypt.
Im honestly recommending scripting to make 1st user register, or otp or somethinf
You could create a seed script using your ORM and setup GitHub actions.
I personally use auth.api.admin.createUser iirc. Give that a try
This is how I handled seeding for my use case
Can you do this if there's no admin user in the database? So when you're starting from 0 users?
yup, that's what i do to create the first user
Here's my code, works just fine for me.

Doesn't require the auth server to be online
Awesome thank you for sharing this. How do you get access to the
createUser
API call? Is that because you have the admin plugin installed?Yup
Makes it super easy
Terrific I'm going to try this.
You're awesome.
im seeing
Property 'createUser' does not exist on type
when I try and access it. What am I doing wrong?
nevermind im a goober, figured it out