How to seed initial admin user on develop/staging/prod to start creating users

I am having trouble creating this initial step for me to progress on, I am also looking into using both the admin and organization plugins to work hand in hand hows to make this possibel
3 Replies
Gabes
Gabes5mo ago
I'm not sure if that answers your question, but if you need to seed yout db, I did something like that yesterday. First, I'd set my oAuth (with github, for instance) and I'd login From there, i'd go to the database, save all information and put it into my seed file
No description
No description
No description
eko
ekoOP5mo ago
@Gabes i see so you directly add this data into the database and don’t use better-auth to signup or createUser. In your case do you need to create a password and/or role ? I’m looking into creating a email and pass authentication system
LatoReset
LatoReset4mo ago
im dealing with same problem, i use an script at startup server and create a user if there are no any users in table
const existingUsers = await db.select().from(user).limit(1)

if (existingUsers.length > 0) {
return { ok: true, message: 'Ya existe un usuario' }
}

const newUser = await auth.api.signUpEmail({
body: {
name,
email,
password,
}
})
const existingUsers = await db.select().from(user).limit(1)

if (existingUsers.length > 0) {
return { ok: true, message: 'Ya existe un usuario' }
}

const newUser = await auth.api.signUpEmail({
body: {
name,
email,
password,
}
})
i think is posible change role directly in database update:
const newUser = await auth.api.createUser({
body: {
name,
email,
password,
role: "admin"
}
})
const newUser = await auth.api.createUser({
body: {
name,
email,
password,
role: "admin"
}
})

Did you find this page helpful?