HyoH
Convex Community11mo ago
2 replies
Hyo

Additional parameters in Email config

I'm using @convex-dev/auth/providers/Email to send verification emails and want to support multiple languages (e.g., 'en', 'ko') based on user settings. However, the current sendVerificationRequest doesn't accept custom parameters like customData to pass locale info, forcing me to hardcode templates (e.g., 'en').

#### Current Code
import { Email } from '@convex-dev/auth/providers/Email';
import { Resend as ResendAPI } from 'resend';
import { alphabet, generateRandomString } from 'oslo/crypto';

type Locale = 'en' | 'ko';
const emailTemplates: Record<Locale, { subject: string; text: (token: string) => string }> = {
  en: { subject: 'Verify your email', text: (token) => `Code: ${token}` },
  ko: { subject: '이메일 인증', text: (token) => `코드: ${token}` },
};

export const ResendOTP = Email({
  id: 'resend-otp',
  apiKey: process.env.AUTH_RESEND_KEY,
  async generateVerificationToken() { return generateRandomString(8, alphabet('0-9')); },
  async sendVerificationRequest({ identifier: email, provider, token }) {
    const template = emailTemplates['en']; // Hardcoded, no locale support
    const resend = new ResendAPI(provider.apiKey);
    await resend.emails.send({ from: 'Auth <onboarding@resend.dev>', to: [email], subject: template.subject, text: template.text(token) });
  },
});


#### Requested Feature
Add support for passing customData (e.g., { locale: 'ko' }) to sendVerificationRequest so I can dynamically select email templates based on locale.

#### Example
const template = emailTemplates[customData?.locale || 'en'];
await resend.emails.send({ ... });


#### Why?
- Enables multi-language email support.
- Increases flexibility for custom email logic.

#### Current Limitation
- sendVerificationRequest only takes { identifier, provider, token }, no way to pass locale.
Was this page helpful?