db seed verified email

I migrated from username auth to email. the email auth requires email verification. Now, when i seed the database, the Users that I created have unverified emails. How can I verify the emails of the records i see in the database during db seed?
2 Replies
kapa.ai
kapa.ai3mo ago
Hi @OrBlatt. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To seed the database with users having verified emails, you need to modify your seed function to include the isEmailVerified field and set it to true. Here's an example of how you can do it based on the code provided in the knowledge sources:
import { sanitizeAndSerializeProviderData } from 'wasp/server/auth'
import { PrismaClient } from '@prisma/client'

async function createUser(
prisma: PrismaClient,
data: { email: string, password: string }
) {
const newUser = await prisma.user.create({
data: {
auth: {
create: {
identities: {
create: {
providerName: 'email',
providerUserId: data.email,
providerData: sanitizeAndSerializeProviderData<'email'>({
password: data.password,
isEmailVerified: true, // Set isEmailVerified to true
emailVerificationSentAt: new Date().toISOString(), // Set the verification sent date to now
}),
},
},
},
},
},
})

return newUser
}
import { sanitizeAndSerializeProviderData } from 'wasp/server/auth'
import { PrismaClient } from '@prisma/client'

async function createUser(
prisma: PrismaClient,
data: { email: string, password: string }
) {
const newUser = await prisma.user.create({
data: {
auth: {
create: {
identities: {
create: {
providerName: 'email',
providerUserId: data.email,
providerData: sanitizeAndSerializeProviderData<'email'>({
password: data.password,
isEmailVerified: true, // Set isEmailVerified to true
emailVerificationSentAt: new Date().toISOString(), // Set the verification sent date to now
}),
},
},
},
},
},
})

return newUser
}
In this example, sanitizeAndSerializeProviderData is used to hash the user's password and set the isEmailVerified field to true. The emailVerificationSentAt field is also set to the current date and time. Please note that this will only mark the email as verified in the database. It won't actually send any verification email. If you want to send a verification email, you can use the sendEmailVerificationEmail function as shown in the Creating a Custom Sign-up Action (https://wasp-lang.dev/docs/auth/email#creating-a-custom-sign-up-action) documentation. Remember to replace 'email' and data.email with the actual email of the user, and data.password with the actual password. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @OrBlatt, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho3mo ago
Could you share your seed script you used to migrate the users?
Want results from more Discord servers?
Add your server