Email Verification Callback after Email Change

When you change the email of a verified user, and provide a callback url, an email is sent to their current email to confirm the change with that callback, but then another email is sent to the new email to mark their new email as verified, but what will the callback url for that email be? How can we customise it?
8 Replies
sebastian
sebastian3mo ago
can you share you auth config?
ikraam
ikraamOP3mo ago
I don't think my config is relevant
sebastian
sebastian3mo ago
Then atleast share your email reset logic
nikatune
nikatune3mo ago
create endpoint
ikraam
ikraamOP3mo ago
explain please?
emailVerification: {
sendVerificationEmail: async ({ user, url, token }, request) => {
await sendEmailVerification({
user,
url,
token,
request
});
},
sendOnSignUp: false,
autoSignInAfterVerification: true,
expiresIn: 3600 // 1 hour
},
emailVerification: {
sendVerificationEmail: async ({ user, url, token }, request) => {
await sendEmailVerification({
user,
url,
token,
request
});
},
sendOnSignUp: false,
autoSignInAfterVerification: true,
expiresIn: 3600 // 1 hour
},
changeEmail: {
enabled: true,
sendChangeEmailVerification: async ({ user, newEmail, url }, request) => {
await sendEmailChangeVerification({
user,
newEmail,
url,
request
});
}
},
changeEmail: {
enabled: true,
sendChangeEmailVerification: async ({ user, newEmail, url }, request) => {
await sendEmailChangeVerification({
user,
newEmail,
url,
request
});
}
},
I've noticed that the email verification to the NEW email after email change uses this callback? But this callback is supposed to be for the OLD email
const result = await authClient.changeEmail({
newEmail: clientAndEmail,
callbackURL: "/admin/account?emailUpdateRedirect=true"
});
const result = await authClient.changeEmail({
newEmail: clientAndEmail,
callbackURL: "/admin/account?emailUpdateRedirect=true"
});
sebastian
sebastian3mo ago
you can include the callback url in your url by exporting the token (if its available in this function, i think so) for e.g. like this: (this is for resetting password, you can see how the endpoint works by console logging the url) const callbackURL = ${BETTER_AUTH_URL}/v1/auth/reset-password/${token}?callbackURL=${SITE_URL}/auth/forget/password if you can't export the token then im out of ideas
ikraam
ikraamOP3mo ago
That's not the issue, the issue is I fire this:
const result = await authClient.changeEmail({
newEmail: clientAndEmail,
callbackURL: "/admin/account?emailUpdateRedirect=true"
});
const result = await authClient.changeEmail({
newEmail: clientAndEmail,
callbackURL: "/admin/account?emailUpdateRedirect=true"
});
OLD email address receives an email to confirm change to the NEW email. I click on the click and get redirected to "/admin/account?emailUpdateRedirect=true" Then Better Auth automatically sends an email verification to the NEW email, the NEW email receives an email, I click on the click and it redirects me to "/admin/account?emailUpdateRedirect=true" also ???
sebastian
sebastian3mo ago
I think that you should try doing this. (as then the callback should be correct on the new email) changeEmail function probably adresses this callbackURL to both sendChangeEmailVerification and sendVerificationEmail, hence why it's the same on old and new email.

Did you find this page helpful?