@@ -89,12 +89,13 @@ const envSchema = z.object({
8989 SMTP_HOST : z . string ( ) . default ( 'smtp.gmail.com' ) ,
9090 SMTP_PORT : z . coerce . number ( ) . default ( 587 ) ,
9191 SMTP_SECURE : z . string ( ) . transform ( ( v ) => v === 'true' ) . default ( 'false' ) ,
92+ // Canonical SMTP credentials — set these in your .env
9293 SMTP_USER : z . string ( ) . default ( '' ) ,
9394 SMTP_PASS : z . string ( ) . default ( '' ) ,
9495 EMAIL_FROM : z . string ( ) . default ( 'noreply@lexai.io' ) ,
95- // Gmail credentials — used directly by the nodemailer transporter
96- MAIL_USER : z . string ( ) . min ( 1 , 'MAIL_USER (Gmail address) is required ') ,
97- MAIL_PASS : z . string ( ) . min ( 1 , 'MAIL_PASS (Gmail App Password) is required ') ,
96+ // Legacy aliases — kept for backwards compatibility; SMTP_USER/SMTP_PASS take precedence
97+ MAIL_USER : z . string ( ) . default ( ' ') ,
98+ MAIL_PASS : z . string ( ) . default ( ' ') ,
9899
99100 // ─── Redis Token TTLs ─────────────────────────────────────
100101 // How long password reset tokens live in Redis (seconds)
@@ -129,6 +130,17 @@ if (!parsed.success) {
129130// Freeze the config to prevent accidental mutation anywhere in the app
130131const env = Object . freeze ( parsed . data ) ;
131132
133+ // ─── Email credential check ────────────────────────────────────────────────
134+ // Ensure at least one SMTP credential pair is configured so emails don't
135+ // silently fail at runtime. SMTP_USER/SMTP_PASS are preferred; MAIL_USER/MAIL_PASS
136+ // are accepted as legacy aliases.
137+ const emailUser = parsed . data . SMTP_USER || parsed . data . MAIL_USER ;
138+ const emailPass = parsed . data . SMTP_PASS || parsed . data . MAIL_PASS ;
139+ if ( ! emailUser || ! emailPass ) {
140+ console . error ( '❌ Email configuration missing: set SMTP_USER and SMTP_PASS (or MAIL_USER and MAIL_PASS) in your .env file.' ) ;
141+ process . exit ( 1 ) ;
142+ }
143+
132144// ─── Production Safety Checks ─────────────────────────────────────────────
133145// Fail fast if placeholder secrets are used in production
134146if ( env . NODE_ENV === 'production' ) {
0 commit comments