passing additional data from authClient to server betterAuth instance

is there a way to pass additional data from client to server when sending emails? For example when sending reset password email, instead of just sending the user's email and callbackUrl as data i also want to send locale which isn't part of the request body so i can generate the email with appropriate language
4 Replies
sebastian
sebastian3d ago
I don't know if I understand correctly, but i would specify the current locale in some variable, then pass it to email sending function.
h3llo
h3lloOP3d ago
yeah, thats the idea, but whats the recommended way of doing to it pass from client to server. For eg on client i do:
await authClient.forgetPassword({
email: value.email,
redirectTo: window.location.origin + "/reset-password",
});
await authClient.forgetPassword({
email: value.email,
redirectTo: window.location.origin + "/reset-password",
});
and on server I do:
export const auth = betterAuth({
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
// send in background
// eslint-disable-next-line @typescript-eslint/require-await
sendResetPassword: async (data) => {
void sendResetPasswordEmail({
locale: ??????
email: data.user.email,
url: data.url,
});
},
},
export const auth = betterAuth({
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
// send in background
// eslint-disable-next-line @typescript-eslint/require-await
sendResetPassword: async (data) => {
void sendResetPasswordEmail({
locale: ??????
email: data.user.email,
url: data.url,
});
},
},
how would i pass locale?
FalconiZzare
FalconiZzare3d ago
AFAIK There isn't a way. You have to make the API endpoint yourself for that.
h3llo
h3lloOP3d ago
can it be done by attaching it to headers or cookies or something?

Did you find this page helpful?