Seed users #284

Closed
opened 2026-03-13 07:40:43 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @dpflucas on GitHub (Nov 26, 2024).

I'm trying to create a seeds file for my Next.js app using better-auth.

This is my current solution:

// prisma/seed.ts

import { prisma } from '../lib/prisma'

async function main() {
  const client = await prisma.user.upsert({
    where: { email: 'client@mail.com' },
    update: {},
    create: {
      id: '1',
      email: 'client@mail.com',
      emailVerified: true,
      createdAt: new Date(),
      updatedAt: new Date(),
    },
  })

  console.log({ client })
}
main()
  .then(async () => {
    await prisma.$disconnect()
  })
  .catch(async (e) => {
    console.error(e)
    await prisma.$disconnect()
    process.exit(1)
  })

The problem is that I don't have a way to set the password. Is there already a way to achieve this?

Originally created by @dpflucas on GitHub (Nov 26, 2024). I'm trying to create a seeds file for my Next.js app using better-auth. This is my current solution: ```ts // prisma/seed.ts import { prisma } from '../lib/prisma' async function main() { const client = await prisma.user.upsert({ where: { email: 'client@mail.com' }, update: {}, create: { id: '1', email: 'client@mail.com', emailVerified: true, createdAt: new Date(), updatedAt: new Date(), }, }) console.log({ client }) } main() .then(async () => { await prisma.$disconnect() }) .catch(async (e) => { console.error(e) await prisma.$disconnect() process.exit(1) }) ``` The problem is that I don't have a way to set the password. Is there already a way to achieve this?
Author
Owner

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

you can use auth.api.signUpEmail instead

@Bekacru commented on GitHub (Nov 26, 2024): you can use `auth.api.signUpEmail` instead
Author
Owner

@dpflucas commented on GitHub (Nov 26, 2024):

Thanks, that works!

@dpflucas commented on GitHub (Nov 26, 2024): Thanks, that works!
Author
Owner

@mintydev789 commented on GitHub (Feb 22, 2025):

What about automatically verifying the seeded user's email?

@mintydev789 commented on GitHub (Feb 22, 2025): What about automatically verifying the seeded user's email?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#284