Unable to send email verification when using Admin plugin createUser

As in the title, when using the admin plugin's authClient.admin.createUser method, the user is created with an emailVerified value of false. On face value this sounds fine but then when subsequently trying to send verificationEmail using authClient.sendVerificationEmail I get a 400 Bad Request error with the code "YOU_CAN_ONLY_SEND_A_VERIFICATION_EMAIL_TO_AN_UNVERIFIED_EMAIL"
const {data: newUser, error} = await authClient.admin.createUser({
email: values.email,
password: "123456",
name: `${values.firstName} ${values.lastName}`,
role: "user",
data: {
firstName: values.firstName,
lastName: values.lastName,
phone: values.phone,
}
})

const {data: verificationEmail, error: verificationEmailError} = await authClient.sendVerificationEmail({
email: values.email,
callbackURL: "/verify-email" // The redirect URL after verification
})
const {data: newUser, error} = await authClient.admin.createUser({
email: values.email,
password: "123456",
name: `${values.firstName} ${values.lastName}`,
role: "user",
data: {
firstName: values.firstName,
lastName: values.lastName,
phone: values.phone,
}
})

const {data: verificationEmail, error: verificationEmailError} = await authClient.sendVerificationEmail({
email: values.email,
callbackURL: "/verify-email" // The redirect URL after verification
})
What is the correct method of adding users via admin functionality?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?