Send params from signIn to sendVerificationRequest using ResendOTP
Hello team!
I'm trying to pass the language of the user when he signs in to the app so that I can send the verification OTP email in that language.
I'm not finding a way to do it.
What I have in my react-native:
await signIn("resend-otp", {
email: parsedEmail,
options: {
language: "en",
},
test: "test", // I was testing with this.
})
And this is the configured Resend provider:
export const ResendOTP = Email({
id: "resend-otp",
apiKey: process.env.AUTH_RESEND_KEY,
maxAge: 60 * 15, // 15 minutes
async generateVerificationToken() {
return generateRandomString(4, alphabet("0-9"))
},
async sendVerificationRequest(params) {
const { identifier: email, provider, token } = params
// Extract language from params.options if it exists, defaulting to "en"
const options = params as unknown as { options?: CustomOptions }
const language = options.options?.language || "en"
console.log("Params:", params)
console.log("Language:", language)
// Create i18n instance for fallback text
const t = createEmailI18n(language)
const resend = new ResendAPI(provider.apiKey)
const { error } = await resend.emails.send({
from: "Shifty <onboarding@test.com>",
to: [email],
subject: t("email.verification.subject"),
text: t("email.verification.code") + ": " + token,
react: ShiftyVerificationEmail({
verificationCode: token,
language: language as Language,
}),
})
if (error) {
throw new Error(JSON.stringify(error))
}
},
})
And here neither in Params logs or Language I can see the desired params.
Thanks in advance!
Let me know what I can do in this case.
6 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
As far as I can tell, this simply isn't supported. Here's where the params object would be passed in if it were: https://github.com/get-convex/convex-auth/blob/2f77702b0e42fa705dfe2af623494682e6a21b49/src/server/implementation/signIn.ts#L151-L169
Looking to see if there's a proper approach for what you're trying to do.
Could also just be an unintentional oversight that args.params is not spread into that function call.
Yeah, I think this is intentional and consistent with Auth.js. That said, it really wouldn't hurt to explicitly pass in the params object to that function, it's already typed to take anything.
Hi @erquhart !
I see, I guess that's why none of that worked for me and why I don't receive anything I pass in the signIn().
What do you think I can do to achive that?
BTW, I'm open to have a quick call if needed in order to see it in action and try to find a solution.
Let me know. Thanks for your response.
The main issue here is Convex Auth defers a lot to Auth.js, to the point of utilizing types and type docs linking directly to that library (e.g., https://labs.convex.dev/auth/api_reference/server#sendverificationrequest). This parity is a good thing for users, so I don't know if diverging from it in an Auth.js method like
sendVerificationRequest()
is very palatable.server - Convex Auth
Authentication library for your Convex backend
Hmm maybe you can register a separate provider per language?
Obviously reusing pretty much everything except the email template. But you would have distinct ids for each provider eg.,
resend-otp-en
and resend-otp-es
, and whatever others. Then you can pick the provider you call straight from the client based on language. I think that would work.Having different providers is a good option to move forward with this.
I've already tried it and it works perfectly.
Thanks a lot for your support, you are doing a great job!!