ab
ab
BABetter Auth
Created by ab on 3/26/2025 in #help
Seeding an admin user
I want to seed an admin user in my Express app. export const auth = betterAuth({ appName: 'LaundryApp', basePath: '/api/auth', trustedOrigins: ['laundryapp://'], database: prismaAdapter(prisma, { provider: 'sqlite', }), plugins: [admin(), expo()], emailAndPassword: { enabled: true, disableSignUp: false, requireEmailVerification: false, minPasswordLength: 8, advanced: { generateId: false, }, maxPasswordLength: 128, autoSignIn: true, sendResetPassword: async ({ user, url, token }) => { console.log('Reset password URL:', url) // TODO }, resetPasswordTokenExpiresIn: 3600, // 1 hour password: { hash: async (password) => { const hashedPassword = await hash(password, 10) console.log(password) return hashedPassword }, verify: async ({ hash, password }) => { const isValid = await compare(password, hash) return isValid }, }, }, }) WHEN I TRY: auth.api.createUser({... I get UNAUTHORIZED ATTEMPTED WORKAROUND I created my user directly with prisma Note: I also added an account record that is linked to the user. But when i try to sign in the user from my frontend I get this : { "code": "INVALID_EMAIL_OR_PASSWORD", "message": "Invalid email or password" } My questions : Is there a diffrent way to login admins ?? I have checked the docs but not seen any Is it possible to seed user into the database using better-auth ?? Or do I have to do it manually and if so , how do i do it correctly
4 replies